TM1640 (16 digit display) with PicBAsic Pro, possible is? How?


Closed Thread
Results 1 to 36 of 36

Hybrid View

  1. #1
    Join Date
    Oct 2011
    Posts
    54


    Did you find this post helpful? Yes | No

    Default Re: TM1640 (16 digit display) with PicBAsic Pro, possible is? How?

    Hi jefrem

    My display took a long time to come, only got it 2 days ago.
    Here is some code to get it going, done mainly by trial & error with a bit of luck.
    The TM1640 is still a bit of a mystery, don't understand it fully yet.
    The code is not 100%, got some more work to do, will keep you posted.

    Phil

    Code:
    ' PIC18F2550 @ 48mHz with USB bootloader
    
    DEFINE OSC 48
    DEFINE RESET_ORG 1000h 
    
        dat_com_inc var byte        'Display command for auto inc address
        dat_com_fix var byte        'Display command for fixed address
        dis_com_off var byte        'Display command OFF
        dis_com_on  var byte        'Display command ON
        address     var byte        'Display address 
        brightness  var byte        'Brightness value (0 - 7)
        dat         var byte        'Data to send to TM1640
        digit       var byte        '7 seg display (0 - 15)
        n           var byte        'Counter
        
        dat_com_inc = %01000000     'Data command ADDRESS auto + 1
        dat_com_fix = %01000100     'Data command FIXED address
        dis_com_off = %10000000     'Switch display OFF
        dis_com_on  = %10001000     'Switch display ON
        brightness  = %00000011     'Display brightness (0 = MIN 7 = MAX)
        address     = %11000000     'Display ADDRESS $00
    
        din        var LATB.7
        sclk       var LATB.6
        
        TRISC = %00111000
        LATC = 0
        TRISB = %00111111
    
        din  = 1                    'Data pin HIGH to start
        sclk = 1                    'Clock pin HIGH to start
        
    '---------- Start of program ------------------------------------
        
        FOR digit = 0 to 16         'Shift display to right 16 times
        dat = address + digit       'Set address to 1st 7seg display
        GOSUB COMMAND:              'Do it
        din = 0 : PAUSE 1  
        sclk = 0 : PAUSEUS 10       'Start transmission process
        FOR n = 0 to 15             'Print 16 characters
            LOOKUP n,[64,64,0,115,6,57,6,127,113,91,109,109,63,0,64,64],dat	
    	    SHIFTOUT din,sclk,0,[dat]  'Print message
    	NEXT
    	PAUSEUS 10 : sclk = 1
        PAUSEUS 10 : din = 1        'End transmission process
        PAUSE 10
        dat = dis_com_on + brightness   'Set brightness
        GOSUB COMMAND:
        PAUSE 500
        NEXT                        'Print at next digit along
    
        END
    '----------------------------------------------------------------
    COMMAND:
        din = 0 : PAUSE 1           'Start transmission
        sclk = 0 : PAUSEUS 10
        SHIFTOUT din,sclk,0,[dat]   'Mode 0 - LSB first, Clock idle low
        PAUSEUS 10 : sclk = 0
        PAUSEUS 10 : din = 0        'End transmission
        PAUSE 10
        RETURN
    '----------------------------------------------------------------

  2. #2
    Join Date
    Aug 2011
    Location
    Manaus - Brazil
    Posts
    24


    Did you find this post helpful? Yes | No

    Default Re: TM1640 (16 digit display) with PicBAsic Pro, possible is? How?

    Hi, Phil. Very thank you for your attention, I hope repay soon by your attention, job and professionalism. Now, I will work around your code and post here any change or improvement I can do.

    I bought other diplay(TM1640) but not yet arrived. I will try with my old Display tonight and say if is ok or no.


    Regards,

  3. #3
    Join Date
    Aug 2011
    Location
    Manaus - Brazil
    Posts
    24


    Did you find this post helpful? Yes | No

    Default Re: TM1640 (16 digit display) with PicBAsic Pro, possible is? How?

    Hello, I tested the Phil code is ok, very good code. I changed the Phil code to not shifting number on display because the original code is shifting when increase any number. On below code is the new change but it add a intercalary digit among all digit.

    This code is a counter, start 0 to 255, this counter is ok but with intercalary digit in all display.
    '************************************************* ***************
    '* Name : TM1640_by_Phil.BAS *
    '* Author : Phil (Sherbrook) *
    '* Notice : Copyright (c) 2013 Phil (Sherbrook) *
    '* : All Rights Reserved *
    '* Date : 23/8/2013 *
    '* Version : 1.0 *
    '* Notes : http://www.picbasic.co.uk/forum/ *
    '* : showthread.php?t=18239 *
    '************************************************* ***************
    ' PIC18F2550 @ 48mHz with USB bootloader

    DEFINE OSC 48
    Define RESET_ORG 1000h

    dat_com_inc var byte 'Display command for auto inc address
    dat_com_fix var byte 'Display command for fixed address
    dis_com_off var byte 'Display command OFF
    dis_com_on var byte 'Display command ON
    address var byte 'Display address
    brightness var byte 'Brightness value (0 - 7)
    dat var byte 'Data to send to TM1640
    digit var byte '7 seg display (0 - 15)
    n var byte 'Counter
    Number var byte 'Number to write
    seed var byte ' Cont 0 to 255
    seedTmp var byte ' Save last Seed Number

    vDigite00 var byte
    vDigite01 var byte
    vDigite02 var byte
    vDigite03 var byte
    vDigite04 var byte
    vDigite05 var byte
    vDigite06 var byte
    vDigite07 var byte
    vDigite08 var byte
    vDigite09 var byte
    vDigite10 var byte
    vDigite11 var byte
    vDigite12 var byte
    vDigite13 var byte
    vDigite14 var byte
    vDigite15 var byte

    dat_com_inc = %01000000 'Data command ADDRESS auto + 1 - 64
    dat_com_fix = %01000100 'Data command FIXED address - 68
    dis_com_off = %10000000 'Switch display OFF - 128
    dis_com_on = %10001000 'Switch display ON - 136
    brightness = %00000000 'Display brightness (0 = MIN 7 = MAX) - 3
    address = %11000000 'Display ADDRESS $00 - 192

    din var LATB.1
    sclk var LATB.0
    LED1 var PORTA.5

    TRISC = %00111000 'Input/Output config Pin
    LATC = 0
    TRISB = %11111100 'Input/Output config Pin

    din = 1 'Data pin HIGH to start
    sclk = 1 'Clock pin HIGH to start
    seed = 0
    '----------------- DIGITS ---------------------------------------
    vDigite00 = 16
    vDigite01 = 16
    vDigite02 = 16
    vDigite03 = 16
    vDigite04 = 16

    vDigite05 = 16 ' Blank Digit

    vDigite06 = 16
    vDigite07 = 16
    vDigite08 = 16
    vDigite09 = 16

    vDigite10 = 16 ' Blank Digit

    vDigite11 = 16
    vDigite12 = 16
    'vDigite13 = 0
    'vDigite14 = 0
    'vDigite15 = 0
    '---------- Start of program ------------------------------------

    main:
    gosub CMDSENDDIGIT
    toggle led1
    pause 20
    seed = seed + 1

    goto main:

    '----------------------------------------------------------------
    COMMAND:
    din = 0 ': PAUSE 1 'Start transmission
    sclk = 0 ': PAUSEUS 10
    SHIFTOUT din,sclk,0,[dat] 'Mode 0 - LSB first, Clock idle low
    'PAUSEUS 10
    sclk = 0
    'PAUSEUS 10
    din = 0 'End transmission
    'PAUSE 10
    RETURN

    CMDSENDDIGIT:

    FOR n = 0 to 15 'Print 16 characters
    gosub CMDNUMBER
    dat = address + (n+1) 'Set address to 1st 7seg display
    GOSUB COMMAND 'Do it
    din = 0 ': PAUSE 1
    sclk = 0 ': PAUSEUS 10 'Start transmission process
    Lookup number,[$3F,$6,$5B,$4F,$66,$6D,$7D,$7,$7F,$67,$77,$7C,$58, $5E,$79,$71,0],dat
    SHIFTOUT din,sclk,0,[dat] 'Print message
    NEXT

    'PAUSEUS 10' :
    sclk = 1
    'PAUSEUS 10' :
    din = 1 'End transmission process
    ' PAUSE 10
    dat = dis_com_on + brightness 'Set brightness
    GOSUB COMMAND
    return

    CMDNUMBER:
    select case n
    case 0
    number = vDigite00
    case 1
    number = vDigite01
    case 2
    number = vDigite02
    case 3
    number = vDigite03
    case 4
    number = vDigite04
    case 5
    number = vDigite05
    case 6
    number = vDigite06
    case 7
    number = vDigite07
    case 8
    number = vDigite08
    case 9
    number = vDigite09
    case 10
    number = vDigite10
    case 11
    number = vDigite11
    case 12
    number = vDigite12
    case 13
    'number = vDigite13
    number = seed DIG 2
    case 14
    'number = vDigite14
    number = seed DIG 1
    case 15
    'number = vDigite15
    number = seed DIG 0
    end select
    return

    end
    '----------------------------------------------------------------


    See the below picture for better understanding.

    Name:  IMG_1198.jpg
Views: 3558
Size:  611.0 KB

    Name:  IMG_1199.jpg
Views: 3724
Size:  607.0 KB


    Regards,

Similar Threads

  1. HSEROUT full 3 digit display of variable howto ?
    By RFsolution in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 24th October 2008, 13:53
  2. Replies: 2
    Last Post: - 14th July 2008, 22:11
  3. Replies: 2
    Last Post: - 22nd January 2008, 14:25
  4. How to display dot on 7-seg , 4 digit
    By chai98a in forum mel PIC BASIC Pro
    Replies: 27
    Last Post: - 19th January 2007, 18:17
  5. SMART Serial 4 Digit LCD Display (SMARD4)
    By paul borgmeier in forum Adverts
    Replies: 0
    Last Post: - 5th January 2005, 05:50

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts