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


Closed Thread
Results 1 to 36 of 36
  1. #1
    Join Date
    Aug 2011
    Location
    Manaus - Brazil
    Posts
    24

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

    Possible is programing TM1640 Display with PicBasic Pro? How???


    I have this code, but does not work. Someone can help me?

    '************************************************* ***************
    '* Name : TM1640-demo.pbp *
    '* Author : Joćo Efrem *
    '* Notice : Copyright (c) 2013 JOĆO EFREM @ 2012 *
    '* : All Rights Reserved *
    '* Date : 22/7/2013 *
    '* Version : 1.0 *
    '* Notes : *
    '* : *
    '************************************************* ***************
    CLEAR ; start with clearing the
    DEFINE OSC 48
    Define RESET_ORG 800h

    Seg_nr var Byte
    Seg_data var Byte
    Info var Byte
    T var Byte
    Test var Byte
    Temp var Byte


    Pin_clk var Portb.0 ' TM1640 clock
    Pin_data var Portb.1 ' TM1640 data

    TRISA=%11111111 ' Configura o PortA como Entrada
    TRISB=%00000000 ' Configura o PortB como Saida
    TRISC=%00000000 ' Configura o PortC como Saida

    INTCON2.7 = 1 ; Turn Pull Up Resitor (PORTB Only) 0=Enable/1=Desable
    ADCON1 = %00001111 ; Sets all ports to digital
    PORTA = %11111111 ; Turn on all PortA Porta = 255
    PORTB = %11111111 ; Turn on all PortB Portb = 255
    PORTC = %11111111 ; Turn on all PortC Portc = 255

    Gosub Tm1640_init ' Ajustar o brilho
    pause 100

    main:


    For Temp = 0 To 15
    Seg_nr = Temp
    Seg_data = Temp
    Gosub Tm1640
    Next Temp

    goto main

    '************************************************* *****************************
    '*** Rotina TM1640 ***
    '*** ***
    '*** Nós usamos duas variįveis??, a saber: ***
    '*** Seg_nr com um intervalo de 0-15 ***
    '*** Seg_data com um intervalo de 0-16, que tudo> 15 = branco ***
    '************************************************* *****************************
    Tm1640:

    If Seg_nr > 15 Then Return
    If Seg_data > 16 Then Seg_data = 16 ' = Branco

    gosub DesenhaDigito

    Info = 68 ' É dobrado de dados
    Gosub Tm1640_zend

    high Pin_clk : high Pin_data

    Info = Seg_nr + 192 ' nśmero do segmento (+ 192)
    Gosub Tm1640_zend

    Info = Seg_data ' dados do segmento
    Gosub Tm1640_zend


    high Pin_clk : high Pin_data ' Barramento de alta

    Return

    '************************************************* *****************************
    '*** Enviar um byte para o display ***
    '************************************************* *****************************
    Tm1640_zend:

    low Pin_clk : low Pin_data

    For T = 1 To 8
    Test = Info And 1
    if test = 1 then
    high pin_data
    else
    low pin_data
    endif
    info = info >> 1
    high Pin_clk
    low Pin_clk
    Next T

    Return

    '************************************************* *****************************
    '*** INIT - Ajusta o brilho dos display's ***
    '************************************************* *****************************
    Tm1640_init:

    Info = 138 ' 143 = Brilho total, 138 = 4/16e
    Gosub Tm1640_zend

    high Pin_clk : high Pin_data

    Return

    '************************************************* *****************************
    '*** Exibe os nśmeros de 0-16(F) nos 16 display's ***
    '************************************************* *****************************

    DesenhaDigito: 'Sem ponto Decimal
    Lookup Seg_data,[$3F,$6,$5B,$4F,$66,$6D,$7D,$7,$7F,$67,$77,$7C,$58, $5E,$79,$71,0],Seg_data ' Sem Ponto Decimal
    return

    End 'end program


    Regard,
    Joćo Efrem
    Last edited by jefrem; - 23rd July 2013 at 15:03.

  2. #2
    Join Date
    Sep 2010
    Location
    Las Vegas, NV
    Posts
    305


    Did you find this post helpful? Yes | No

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

    Well, without looking at the datasheet this is what I can tell you:

    Define RESET_ORG 800h needs to be upper case. i.e. DEFINE RESET_ORG 800h

    Then you set all of PortA to inputs, TRISA=%11111111 ' Configura o PortA como Entrada (I think at least. I don't do Brazilian.) and then turn them on(?) with PORTA = %11111111 ; Turn on all PortA Porta = 255. I just don't think that's right. Can you even make that happen when the port is set to input?

    Lots of people could be more helpful if you'd do it in English.

    It would also be helpful for you to tell us what doesn't work. Do you get any display using this program? How about another program? Is the display completely dead or does it do anything? A schematic may also be good if the display doesn't do have any display.

    Good luck

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


    Did you find this post helpful? Yes | No

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

    Hellow AvionicsMaster1, thank you for your atencion.

    So, when write this code in my PIC18F2550 nothing happens. Nothing display lights. I've tried other programs but nothing happens.

    Below has three URL with datasheet, Arduino example and reference library for this display..

    Arduino Example: http://tronixstuff.wordpress.com/201...splay-modules/
    Ic Datasheet: http://www.titanmec.com/doce/product-detail-180.html
    Reference site: https://code.google.com/p/tm1638-library/

    Hope you can help me, grateful for your the attention.
    Last edited by jefrem; - 24th July 2013 at 15:56.

  4. #4
    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?

    [QUOTE=jefrem;121502]Possible is programing TM1640 Display with PicBasic Pro? How???


    I have this code, but does not work. Someone can help me?

    '************************************************* ***************
    '* Name : TM1640-demo.pbp *
    '* Author : Joćo Efrem *
    '* Notice : Copyright (c) 2013 JOĆO EFREM @ 2012 *
    '* : All Rights Reserved *
    '* Date : 22/7/2013 *
    '* Version : 1.0 *
    '* Notes : *
    '* : *
    '************************************************* ***************
    CLEAR ; start with clearing the
    DEFINE OSC 48
    DEFINE RESET_ORG 800h

    Seg_nr var Byte
    Seg_data var Byte
    Info var Byte
    T var Byte
    Test var Byte
    Temp var Byte
    LED1 var PORTC.5

    Pin_clk var Portb.0 ' TM1640 clock
    Pin_data var Portb.1 ' TM1640 data

    TRISA=%11111111 ' Port PortA as Input
    TRISB=%00000000 ' Port PortB as Output
    TRISC=%00000000 ' Port PortC as Output

    INTCON2.7 = 1 ; Turn Pull Up Resitor (PORTB Only) 0=Enable/1=Desable
    ADCON1 = %00001111 ; Sets all ports to digital
    PORTA = %00000000 ; Turn off all PortA
    PORTB = %00000000 ; Turn off all PortB
    PORTC = %00000000 ; Turn off all PortC

    Gosub Tm1640_init ' Light Intensity of display
    pause 100

    main:


    For Temp = 0 To 15
    Seg_nr = Temp
    Seg_data = Temp
    Gosub Tm1640
    Next Temp

    TOGGLE LED1 ' This normally functioning LED1

    goto main

    '************************************************* *****************************
    '*** Routin TM1640 ***
    '*** ***
    '*** There two variable. ***
    '*** Seg_nr = display number 0-15 (16 Displays) ***
    '*** Seg_data = Value send for display (7 Segment date) ***
    '************************************************* *****************************
    Tm1640:

    If Seg_nr > 15 Then Return
    If Seg_data > 16 Then Seg_data = 16 ' = Blank Display

    gosub DisplayNumberSegment

    Info = 68
    Gosub Tm1640_zend

    high Pin_clk : high Pin_data

    Info = Seg_nr + 192 ' Display position (+ 192)
    Gosub Tm1640_zend

    Info = Seg_data ' Number date to write in display
    Gosub Tm1640_zend


    high Pin_clk : high Pin_data

    Return

    '************************************************* *****************************
    '*** Send display date and clock Routine ***
    '************************************************* *****************************
    Tm1640_zend:

    low Pin_clk : low Pin_data ' Put low signal in Pin_clk and Pin_data

    For T = 1 To 8 ' Test bitwise and send for 'Pind_data' the state of each bit.
    Test = Info And 1
    if test = 1 then
    high pin_data
    else
    low pin_data
    endif
    info = info >> 1
    high Pin_clk ' Send the pulse clock(Pin_clk) + date(Pin_data)
    low Pin_clk
    Next T

    Return

    '************************************************* *****************************
    '*** INIT - Light Intensity of display Routine ***
    '************************************************* *****************************
    Tm1640_init:

    Info = 138 ' 143 = fully Light Intensity, 138 = 4/16e
    Gosub Tm1640_zend

    high Pin_clk : high Pin_data

    Return

    '************************************************* *****************************
    '*** Show the display numbers 0-16(F) on 16 display ***
    '************************************************* *****************************

    DisplayNumberSegment: 'Display without decimal point
    Lookup Seg_data,[$3F,$6,$5B,$4F,$66,$6D,$7D,$7,$7F,$67,$77,$7C,$58, $5E,$79,$71,0],Seg_data '
    return

    End 'end program

  5. #5
    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?

    This is circuit diagram.

    Name:  Esquema_TM1640_Display.JPG
Views: 7569
Size:  52.3 KB
    Last edited by jefrem; - 24th July 2013 at 16:30.

  6. #6
    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

    I wrote the following code for the JY-MCU JY-LKM1638 using the Microcode loader and

    PicBasic assembler.

    It displays the numbers 0 to 7 on the 7seg displays, the buttons pressed as binary

    representation on a LCD display and cycles the LEDs off -> green -> red. Hope this helps.

    Phil

    [code
    @ DEVICE PIC16F873A, XT_OSC 'Xtal OSC
    @ DEVICE PIC16F873A, WDT_OFF 'WDT off
    @ DEVICE PIC16F873A, PWRT_ON 'Power-up timer on
    @ DEVICE PIC16F873A, BOD_OFF 'Brown-out detect off

    DEFINE LOADER_USED 1
    DEFINE OSC 4
    DEFINE LCD_DREG PORTB
    DEFINE LCD_DBIT 4
    DEFINE LCD_RSREG PORTB
    DEFINE LCD_RSBIT 2
    DEFINE LCD_EREG PORTB
    DEFINE LCD_EBIT 3

    TRISC = %00000000
    TRISB = %00000001 'LCD display / I/R input
    TRISA = %11000000 'A.6 & A.7 Bootloader
    ADCON1 = %00000110 'PortA all digital

    strobe var PORTA.4
    sda VAR PORTA.3
    scl VAR PORTA.2

    fix_addr con $C0 'Start address of 7 segs & LEDs
    '($C0 = %11000000 = address $00)
    auto_addr con $40 'Address of auto-increment mode
    read_mode con $42 'Address to read switches

    char var byte 'LOOKUP offset for 7 seg code
    disp_addr var byte 'Offset from display start address
    '(ODD = LED, EVEN = 7seg)
    data_io var byte 'Data IN / OUT
    disp_brit var byte 'Display brightness
    seg_val var byte 'Code to send to 7 seg displays
    'LEDs 0 = OFF, 1 = RED, 2 = GREEN
    bank var byte '0 = Left 7 segment, 2 = next segment
    '...... 14 = Right 7 segment
    sw1 var byte 'Byte 1 of switch read
    sw2 var byte 'Byte 2 of switch read
    sw3 var byte 'Byte 3 of switch read
    sw4 var byte 'Byte 4 of switch read
    switch var byte 'Switch pressed as binary number
    counter var byte 'General counter
    counter1 var byte

    strobe = 1 'Set strobe pin high
    SDA = 1 'Set data pin high
    SCL = 1 'Set clock pin high
    disp_brit = $88 'Set minimum brightness (Max = $8F)
    bank = 0
    DISP_ADDR = 0
    '----------------------------------------------------------------
    lcdout $FE,1 'Clear LCD
    pause 100
    lcdout $FE,$80,"Switch "
    gosub clear_char: 'Clear 7 seg displays & LEDs
    gosub display: 'Write Chars to 7 seg display

    MAIN:
    for DISP_ADDR = 1 to 15 step 2
    gosub write_display 'Write to LEDs display
    seg_val = seg_val + 1
    if seg_val > 2 then seg_val = 0
    next
    for counter1 = 0 to 50 'Pause for 1 sec
    pause 20
    gosub GET_SWITCH: 'Check switches
    next
    goto MAIN:

    end
    '----------------------------------------------------------------
    DISPLAY:
    gosub WRITE_MODE:
    DISP_ADDR = bank + 0
    char = 0 'Print "0"
    gosub lookup_char:
    gosub write_display:
    DISP_ADDR = bank + 2
    char = 1 'Print "1"
    gosub lookup_char:
    gosub write_display:
    DISP_ADDR = bank + 4
    char = 2 'Print "2"
    gosub lookup_char:
    gosub write_display:
    DISP_ADDR = bank + 6
    char = 3 'Print "3"
    gosub lookup_char:
    gosub write_display:
    DISP_ADDR = bank + 8
    char = 4 'Print "4"
    gosub lookup_char:
    gosub write_display:
    DISP_ADDR = bank + 10
    char = 5 'Print "5"
    gosub lookup_char:
    gosub write_display:
    DISP_ADDR = bank + 12
    char = 6 'Print "6"
    gosub lookup_char:
    gosub write_display:
    DISP_ADDR = bank + 14
    char = 7 'Print "7"
    gosub lookup_char:
    gosub write_display:
    gosub display_brit: 'Set Display brightness
    return
    '----------------------------------------------------------------
    CLEAR_CHAR: 'Clear LEDs & 7 seg displays
    gosub write_mode:
    STROBE = 0
    data_io = FIX_ADDR 'Set start address
    gosub send_char:
    for counter = 1 to 16
    data_io = 0 'Blank display
    gosub send_char:
    next
    Strobe = 1
    return
    '----------------------------------------------------------------
    CLEAR_LEDS: 'Clear LEDs only
    gosub write_mode:
    for DISP_ADDR = 1 to 15 step 2
    SEG_VAL = 0 'Turns LEDs OFF
    gosub write_display:
    next
    gosub display_brit 'Set brightness
    return
    '----------------------------------------------------------------
    SEND_CHAR:
    shiftout SDA,SCL,4,[data_io]'LSB first, CLOCK idle HIGH
    return
    '----------------------------------------------------------------
    LOOKUP_CHAR:
    ' lookup char,[1,2,4,8,16,32,64,128],seg_val
    ' Turns on a different segment on each display
    lookup char,[$3F,$06,$5B,$4F,$66,$6D,$7D,$07,_
    $7F,$6F,$77,$7C,$58,$5E,$79,$71,$0],SEG_VAL
    'Value for 0,1,2,3,4,5,6,7,8,9,A,b,c,d,E,F,(Blank)
    return
    '----------------------------------------------------------------
    GET_SWITCH:
    data_io = read_mode 'Set to read 4 bytes
    strobe = 0
    gosub SEND_CHAR:
    shiftin sda,scl,6,[sw1,sw2,sw3,sw4] '4 byte switch read
    'MSB first, Read data after clock
    strobe = 1
    switch.7 = sw1.7 'Convert 4 switch read bytes
    switch.6 = sw2.7 'into a single byte
    switch.5 = sw3.7 'and display on LCD
    switch.4 = sw4.7 'as a binary number
    switch.3 = sw1.3 'Left hand 4 switches are in
    switch.2 = sw2.3 'bit 7 of the 4 bytes
    switch.1 = sw3.3 'Right hand 4 switches are in
    switch.0 = sw4.3 'bit 3 of the 4 bytes
    ' switch = sw1 + (sw2 / 2) + (sw3 / 4) + (sw4 / 8)
    ' Alternative way to convert but uses more bytes
    lcdout $FE,$88,bin8 switch
    return
    '----------------------------------------------------------------
    DISPLAY_BRIT:
    data_io = disp_brit
    STROBE = 0
    gosub send_char:
    STROBe = 1
    return
    '----------------------------------------------------------------
    WRITE_DISPLAY:
    data_io = FIX_ADDR + DISP_ADDR
    strobe = 0
    gosub send_char:
    data_io = SEG_VAL
    gosub send_char:
    STROBE = 1
    gosub display_brit:
    return
    '----------------------------------------------------------------
    WRITE_MODE:
    DATA_IO = AUTO_ADDR
    strobe = 0
    gosub send_char:
    strobe = 1
    return
    '================================================= ===============
    /code]

  7. #7
    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?

    Hellow Sherbrook, I will try to this your code and give news.

  8. #8
    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, Sherbrook.

    I made change below but yet not works. I will buy another display, I thing this display is wrong, but I don't have sure.


    '************************************************* ***************
    '* Name : LKM1638.BAS *
    '* Author : Sherbrook' *
    '* Notice : Microcode loader and PicBasic assembler. *
    '* : All Rights Reserved *
    '* Date : 24/7/2013 *
    '* Version : v 2.0 *
    '* Notes : *
    '* : *
    '************************************************* ***************
    '@ DEVICE PIC16F873A, XT_OSC 'Xtal OSC
    '@ DEVICE PIC16F873A, WDT_OFF 'WDT off
    '@ DEVICE PIC16F873A, PWRT_ON 'Power-up timer on
    '@ DEVICE PIC16F873A, BOD_OFF 'Brown-out detect off
    CLEAR ; start with clearing the
    DEFINE OSC 48
    Define RESET_ORG 800h


    'strobe var PORTA.4
    sda VAR PORTB.1
    scl VAR PORTB.0

    TRISA=%11111111 ' Configura o PortA como Entrada
    TRISB=%00000000 ' Configura o PortB como Saida
    TRISC=%00000000 ' Configura o PortC como Saida

    INTCON2.7 = 1 ' Turn Pull Up Resitor (PORTB Only) 0=Enable/1=Desable
    ADCON1 = %00001111 ' Sets all ports to digital
    PORTA = %00000000 ' Turn off all PortA
    PORTB = %00000000 ' Turn off all PortB
    PORTC = %00000000 ' Turn off all PortC
    '================================================= =======

    'TRISC = %00000000
    'TRISB = %00000001 ' LCD display / I/R input
    'TRISA = %11000000 ' A.6 & A.7 Bootloader
    'ADCON1 = %00000110 ' PortA all digital

    fix_addr con $C0 ' Start address of 7 segs & LEDs '($C0 = %11000000 = address $00)
    auto_addr con $40 ' Address of auto-increment mode (Change to $44-IC1640)
    'read_mode con $42 ' Address to read switches

    char var byte ' LOOKUP offset for 7 seg code
    disp_addr var byte ' Offset from display start address (ODD = LED, EVEN = 7seg)
    data_io var byte ' Data IN / OUT
    disp_brit var byte ' Display brightness
    seg_val var byte ' Code to send to 7 seg displays LEDs 0 = OFF, 1 = RED, 2 = GREEN
    bank var byte ' 0 = Left 7 segment, 2 = next segment ...... 14 = Right 7 segment
    'sw1 var byte ' Byte 1 of switch read
    'sw2 var byte ' Byte 2 of switch read
    'sw3 var byte ' Byte 3 of switch read
    'sw4 var byte ' Byte 4 of switch read
    'switch var byte ' Switch pressed as binary number
    counter var byte ' General counter
    counter1 var byte

    'strobe = 1 ' Set strobe pin high
    SDA = 1 ' Set data pin high
    SCL = 1 ' Set clock pin high
    disp_brit = $88 ' Set minimum brightness (Max = $8F)
    bank = 0
    DISP_ADDR = 0

    '----------------------------------------------------------------
    gosub clear_char: 'Clear 7 seg displays & LEDs
    gosub display: 'Write Chars to 7 seg display

    MAIN:

    for DISP_ADDR = 1 to 15 step 2
    gosub write_display 'Write to LEDs display
    seg_val = seg_val + 1
    if seg_val > 2 then seg_val = 0
    next

    for counter1 = 0 to 50 'Pause for 1 sec
    pause 20
    next

    goto MAIN:

    end
    '----------------------------------------------------------------
    DISPLAY:
    gosub WRITE_MODE:
    DISP_ADDR = bank + 0
    char = 0 'Print "0"
    gosub lookup_char:
    gosub write_display:

    DISP_ADDR = bank + 2
    char = 1 'Print "1"
    gosub lookup_char:
    gosub write_display:

    DISP_ADDR = bank + 4
    char = 2 'Print "2"
    gosub lookup_char:
    gosub write_display:

    DISP_ADDR = bank + 6
    char = 3 'Print "3"
    gosub lookup_char:
    gosub write_display:

    DISP_ADDR = bank + 8
    char = 4 'Print "4"
    gosub lookup_char:
    gosub write_display:

    DISP_ADDR = bank + 10
    char = 5 'Print "5"
    gosub lookup_char:
    gosub write_display:

    DISP_ADDR = bank + 12
    char = 6 'Print "6"
    gosub lookup_char:
    gosub write_display:

    DISP_ADDR = bank + 14
    char = 7 'Print "7"
    gosub lookup_char:
    gosub write_display:
    gosub display_brit: 'Set Display brightness

    return

    '----------------------------------------------------------------
    CLEAR_CHAR: 'Clear LEDs & 7 seg displays
    gosub write_mode:

    'STROBE = 0
    data_io = FIX_ADDR 'Set start address
    gosub send_char:

    for counter = 1 to 16
    data_io = 0 'Blank display
    gosub send_char:
    next

    'Strobe = 1

    return

    '----------------------------------------------------------------
    CLEAR_LEDS: 'Clear LEDs only
    gosub write_mode:

    for DISP_ADDR = 1 to 15 step 2
    SEG_VAL = 0 'Turns LEDs OFF
    gosub write_display:
    next

    gosub display_brit 'Set brightness

    return

    '----------------------------------------------------------------
    SEND_CHAR:
    shiftout SDA,SCL,4,[data_io]'LSB first, CLOCK idle HIGH
    return

    '----------------------------------------------------------------
    LOOKUP_CHAR:
    ' lookup char,[1,2,4,8,16,32,64,128],seg_val
    ' Turns on a different segment on each display
    lookup char,[$3F,$06,$5B,$4F,$66,$6D,$7D,$07,$7F,$6F,$77,$7C,$5 8,$5E,$79,$71,$0],SEG_VAL
    'Value for 0,1,2,3,4,5,6,7,8,9,A,b,c,d,E,F,(Blank)
    return

    '----------------------------------------------------------------
    DISPLAY_BRIT:
    data_io = disp_brit
    'STROBE = 0
    gosub send_char:

    'STROBe = 1

    return

    '----------------------------------------------------------------
    WRITE_DISPLAY:
    data_io = FIX_ADDR + DISP_ADDR
    'strobe = 0
    gosub send_char:

    data_io = SEG_VAL
    gosub send_char:

    'STROBE = 1
    gosub display_brit:

    return

    '----------------------------------------------------------------
    WRITE_MODE:
    DATA_IO = AUTO_ADDR
    'strobe = 0
    gosub send_char:

    'strobe = 1

    return
    '================================================= ================

    Thank you for your attention.

  9. #9
    Join Date
    Sep 2010
    Location
    Las Vegas, NV
    Posts
    305


    Did you find this post helpful? Yes | No

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

    Every link I find about this display is coupled with Arduino and they always reference a library. I wasn't able to find any libraries written for PBP so it might never work on Basic until you can find the library for it.

  10. #10
    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?

    I continuous search article about this Display (TM1640) on internet, if find any thing about this device, I post he!

  11. #11
    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?

    I see you are using USB loader and are stuck with 48mHz. Perhaps this is too fast for TM1640. Have you got a slower PIC to try with.
    My code does work at 4mHz.
    Have you got the datasheet for TM1640?
    Phil

  12. #12
    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?

    Exact, I've use Bootloader with 48MHz. I have the Datasheet. I'll try with 16F628A and return.

  13. #13
    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 Joćo
    Have ordered a JY-MCU 16X display. I should get it in about 2 weeks. Will let you know how I get on.
    Phil

  14. #14
    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,

    I tried buy other display on dx.com but is sold out. Where you buy? Do you have an PIC18F with clock 48Mhz famile for make this new test ?

    Regards,

  15. #15
    Join Date
    Mar 2003
    Location
    Commerce Michigan USA
    Posts
    1,166


    Did you find this post helpful? Yes | No

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

    Just set the DEFINE SHIFT_PAUSEUS 3 which will set the clock to a minimum of 3 us. that will slow it down to 333 Khz. which is just below the maximum of 450 Khz.
    Dave Purola,
    N8NTA
    EN82fn

  16. #16
    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 Dave Purola,

    I tried set this but nothing happens, I need buy other display for sure if my is good or no I think my display is bad, I don't have sure.

    Thank you for your attention.
    Last edited by jefrem; - 30th July 2013 at 13:07.

  17. #17
    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?

    Display is ordered from www.fasttech.com. I have not ordered from them before so do not know what the service is like yet.
    I have a PIC18F2550 with USB bootloader to try it on.

    Phil

  18. #18
    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,

    I used this code on my test. When possible try this so.


    '************************************************* ***************
    '* Name : LKM1640.BAS *
    '* Author : Sherbrook' *
    '* Notice : Microcode loader and PicBasic assembler. *
    '* : All Rights Reserved *
    '* Date : 24/7/2013 *
    '* Version : v 2.0 *
    '* Notes : *
    '* : *
    '************************************************* ***************
    CLEAR ; start with clearing the

    DEFINE OSC 48
    Define RESET_ORG 800h
    DEFINE SHIFT_PAUSEUS 300
    Include "modedefs.bas" ' Include shift modes


    'DEFINE LOADER_USED 1
    ''DEFINE OSC 4
    'DEFINE LCD_DREG PORTA
    'DEFINE LCD_DBIT 4
    'DEFINE LCD_RSREG PORTA
    'DEFINE LCD_RSBIT 2
    'DEFINE LCD_EREG PORTA
    'DEFINE LCD_EBIT 3

    '================================================= =======
    LED1 var PORTA.5
    'strobe var PORTA.4
    SDA VAR PORTB.1
    SCL VAR PORTB.0

    TRISA=%00000000 ' Configura o PortA como Saida
    TRISB=%00000000 ' Configura o PortB como Saida
    TRISC=%00000000 ' Configura o PortC como Saida

    INTCON2.7 = 1 ' Turn Pull Up Resitor (PORTB Only) 0=Enable/1=Desable
    ADCON1 = %00001111 ' Sets all ports to digital 00001111
    PORTA = %00000000 ' Turn off all PortA
    PORTB = %00000000 ' Turn off all PortB
    PORTC = %00000000 ' Turn off all PortC

    '================================================= =======


    'TRISC = %00000000
    'TRISB = %00000001 ' LCD display / I/R input
    'TRISA = %11000000 ' A.6 & A.7 Bootloader
    'ADCON1 = %00000110 ' PortA all digital



    fix_addr con $C0 ' Start address of 7 segs & LEDs '($C0 = %1100-0000 = address $00) - 192
    auto_addr con $44 ' Address of auto-increment mode - 40/64/0100-0000 - 44/68/0100-0100
    'read_mode con $42 ' Address to read switches - 42/66/0100-0010

    char var byte ' LOOKUP offset for 7 seg code
    disp_addr var byte ' Offset from display start address (ODD = LED, EVEN = 7seg)
    data_io var byte ' Data IN / OUT
    disp_brit var byte ' Display brightness
    seg_val var byte ' Code to send to 7 seg displays LEDs 0 = OFF, 1 = RED, 2 = GREEN
    bank var byte ' 0 = Left 7 segment, 2 = next segment ...... 14 = Right 7 segment
    'sw1 var byte ' Byte 1 of switch read
    'sw2 var byte ' Byte 2 of switch read
    'sw3 var byte ' Byte 3 of switch read
    'sw4 var byte ' Byte 4 of switch read
    'switch var byte ' Switch pressed as binary number
    counter var byte ' General counter
    counter1 var byte

    'high strobe 'strobe = 1 ' Set strobe pin high
    high SDA ' Set data pin high
    high SCL ' Set clock pin high
    disp_brit = $8f ' Set minimum brightness (Max = $8F) - 88/136/1000-1000
    bank = 0
    DISP_ADDR = 0

    '----------------------------------------------------------------
    'lcdout $FE,1 ' Clear LCD
    'pause 100
    'lcdout $FE,$80,"Switch "

    gosub BLINK_LED_START:
    gosub clear_char: 'Clear 7 seg displays & LEDs
    gosub display: 'Write Chars to 7 seg display

    MAIN:


    for DISP_ADDR = 0 to 16
    gosub write_display 'Write to LEDs display
    seg_val = seg_val + 1
    if seg_val > 2 then seg_val = 0
    next

    'for counter1 = 0 to 50 'Pause for 1 sec
    ' pause 20
    ' gosub GET_SWITCH: 'Check switches
    'next

    toggle led1

    goto MAIN

    END
    '----------------------------------------------------------------
    DISPLAY:
    gosub WRITE_MODE

    DISP_ADDR = fix_addr 'bank + 0
    char = 0 'Print "0"
    gosub lookup_char
    gosub write_display

    DISP_ADDR = bank + 2
    char = 1 'Print "1"
    gosub lookup_char
    gosub write_display

    DISP_ADDR = bank + 4
    char = 2 'Print "2"
    gosub lookup_char
    gosub write_display

    DISP_ADDR = bank + 6
    char = 3 'Print "3"
    gosub lookup_char
    gosub write_display

    DISP_ADDR = bank + 8
    char = 4 'Print "4"
    gosub lookup_char
    gosub write_display

    DISP_ADDR = bank + 10
    char = 5 'Print "5"
    gosub lookup_char
    gosub write_display

    DISP_ADDR = bank + 12
    char = 6 'Print "6"
    gosub lookup_char
    gosub write_display

    DISP_ADDR = bank + 14
    char = 7 'Print "7"
    gosub lookup_char
    gosub write_display

    DISP_ADDR = bank + 16
    char = 8 'Print "8"
    gosub lookup_char
    gosub write_display

    DISP_ADDR = bank + 18
    char = 9 'Print "9"
    gosub lookup_char
    gosub write_display

    DISP_ADDR = bank + 20
    char = 10 'Print "10"
    gosub lookup_char
    gosub write_display

    DISP_ADDR = bank + 22
    char = 11 'Print "11"
    gosub lookup_char
    gosub write_display

    DISP_ADDR = bank + 24
    char = 12 'Print "12"
    gosub lookup_char
    gosub write_display

    DISP_ADDR = bank + 26
    char = 13 'Print "13"
    gosub lookup_char
    gosub write_display

    DISP_ADDR = bank + 28
    char = 14 'Print "14"
    gosub lookup_char
    gosub write_display

    DISP_ADDR = bank + 30
    char = 15 'Print "15"
    gosub lookup_char
    gosub write_display

    gosub display_brit 'Set Display brightness

    return

    '----------------------------------------------------------------
    CLEAR_CHAR: 'Clear LEDs & 7 seg displays
    gosub write_mode

    'STROBE = 0
    data_io = FIX_ADDR 'Set start address
    gosub send_char

    for counter = 1 to 16
    data_io = 0 'Blank display
    gosub send_char
    next

    'Strobe = 1

    return

    '----------------------------------------------------------------
    'CLEAR_LEDS: 'Clear LEDs only
    ' gosub write_mode
    '
    ' for DISP_ADDR = 1 to 15 step 2
    ' SEG_VAL = 0 'Turns LEDs OFF
    ' gosub write_display
    ' next
    '
    ' gosub display_brit 'Set brightness
    '
    'return

    '----------------------------------------------------------------
    SEND_CHAR:
    shiftout SDA,SCL,4,[data_io]'LSB first, CLOCK idle HIGH
    return

    '----------------------------------------------------------------
    LOOKUP_CHAR:
    ' lookup char,[1,2,4,8,16,32,64,128],seg_val
    ' Turns on a different segment on each display
    lookup char,[$3F,$06,$5B,$4F,$66,$6D,$7D,$07,$7F,$6F,$77,$7C,$5 8,$5E,$79,$71,$0],SEG_VAL
    'Value for 0,1,2,3,4,5,6,7,8,9,A,b,c,d,E,F,(Blank)
    return

    '----------------------------------------------------------------
    DISPLAY_BRIT:
    data_io = disp_brit
    'STROBE = 0
    gosub send_char

    'STROBe = 1

    return

    '----------------------------------------------------------------
    WRITE_DISPLAY:
    data_io = FIX_ADDR + DISP_ADDR
    'strobe = 0
    gosub send_char
    data_io = SEG_VAL
    gosub send_char
    'STROBE = 1
    gosub display_brit

    return

    '----------------------------------------------------------------
    WRITE_MODE:
    DATA_IO = AUTO_ADDR
    'strobe = 0
    gosub send_char

    'strobe = 1

    return

    '----------------------------------------------------------------
    BLINK_LED_START:
    high led1
    pause 200

    low led1
    pause 100

    high led1
    pause 200

    low led1
    pause 100

    high led1
    pause 200

    low led1
    pause 100
    return

    '================================================= ================

  19. #19
    Join Date
    Oct 2004
    Posts
    440


    Did you find this post helpful? Yes | No

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

    jefrem

    It may make little difference but try removing the colons after the gosubs in the following lines:
    Code:
     gosub BLINK_LED_START:
     gosub clear_char: 'Clear 7 seg displays & LEDs
     gosub display: 'Write Chars to 7 seg display

    Norm

  20. #20
    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 Norm, I will change this your tips and return.

  21. #21
    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 Norm, I tried this new change but not worked.

    Regards,

  22. #22
    Join Date
    Sep 2010
    Location
    Las Vegas, NV
    Posts
    305


    Did you find this post helpful? Yes | No

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

    Just out of curiousity, what does this line do in your code?

    Define RESET_ORG 800h

  23. #23
    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, This "Define RESET_ORG 800h" line is used for Microchip USB bootloader.

    Regards,

  24. #24
    Join Date
    Sep 2010
    Location
    Las Vegas, NV
    Posts
    305


    Did you find this post helpful? Yes | No

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

    Well, I've pointed this out before but the Define must be caps. If it's part of the bootloader that may be why it isn't loading. Which may be the issue.

    I honestly think you need to take a step back and go for blinking a LED. A quick review of your posts only indicate nothing is working. If you're communicating properly with the PIC the LED will indicate that.

  25. #25
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,519


    Did you find this post helpful? Yes | No

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

    AvionicMaster1,
    Can you give us some reference supporting your statement regarding the case sensitivity? I ask because I think you've got it wrong and I'll support that by quoting Darrel from another thread:
    The word "define" is a PBP statement, and PBP is not case sensitive. So it doesn't matter what case DeFiNe is.
    What follows "define" is passed on to the assembler, and MPASM IS case sensitive.
    So in this case the line Define RESET_ORG 800h is perfectly valid since RESET_ORG is all upper case.

    Again, it's NOT the word define that must be upper case, it is what follows the word define that must match the case of however it's being used elsewhere.
    In PBP's case (no pun intended) all defines are upper case but if you use or write an assembly routine which has some constants you can set it may, or may not, be all upper case. It might be myParticularSetting. If you then would try to set that to 123 by doing DEFINE MYPARTICULARSETTING 123 it wouldn't work since the assembly code is looking for myParticularSetting.

    Apart from that I'm afraid I don't have much to contribute to this thread....

    /Henrik.

  26. #26
    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, my project has a LED. I use TOGGLE command in MAIN route and not has problem, the LED blink normally. In other words, the communication PIC is worked.


    Regards,

  27. #27
    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 HenrikOlsson,

    Thank you by your contribution.


    Regards,

  28. #28
    Join Date
    Sep 2010
    Location
    Las Vegas, NV
    Posts
    305


    Did you find this post helpful? Yes | No

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

    Well, from the PBP3 manual shows this for asm interrups which although doesn't specify DEFINE needs to be in caps they are all written that way.

    6.2.2 DEFINEs
    PBP offers a DEFINE to specify the name of the interrupt service routine label. The
    label refers to the Assembly Language label that marks the beginning of your
    service routine.
    DEFINE INTHAND Label
    For devices with multiple priority interrupts, PBP offers a single additional DEFINE
    that allows you to specify a second label for a second service routine. This routine
    will be used for low-priority interrupts.
    DEFINE INTLHAND Label

    And here it says they need to be in caps even a line that has the DEFINE RESET_ORG uses caps so I assume it needs caps.

    2.3.2 Global DEFINEs
    Other DEFINEs that are important, though less frequently used, are:
    DEFINE NO_CLRWDT 1 'Don’t insert CLRWDTs
    DEFINE LOADER_USED 1 'Bootloader is being used
    DEFINE OSCCAL_1K 1 'Set OSCCAL for 1K PIC12
    DEFINE OSCCAL_2K 1 'Set OSCCAL for 2K PIC12
    DEFINE RESET_ORG 0h 'Change reset address for PIC18
    DEFINE INTHAND Label 'Assign assembler interrupt
    handler label
    DEFINE INTLHAND Label 'Assign assembler low priority
    interrupt handler label for
    PIC18
    See section 8.6 for a condensed list of DEFINEs with brief explanations.

    2.3.3 DEFINEs defined
    For the user familiar with Assembly Language, the major clue to understanding is
    that DEFINEs in PBP are converted literally to Assembly Language #DEFINE
    directives.
    For the practical PBP user, there are a couple of fundamental points to consider:
    1) DEFINEs are CASE SENSITIVE!
    2) Specific DEFINEs are generally associated with PBP commands. The
    command pages will describe how the relevant DEFINEs affect the
    operation of each command.
    DEFINEs are used by PBP to change the generated Assembly Language that
    makes up the compiled program. A DEFINE might simply change an internal
    register setting, or it might result in the use of an alternative Assembly Language
    routine to accomplish a task.

    For what it's worth I'm not an experienced programmer but If I'm wrong I'd like to know for future use. In the few prorams I've written I've always had to use caps for the defines to work but I haven't been calling asm routines. So I'd at least try it to see if it matters.

    It appears this isn't the problem anyway. If I am wrong I apologize for any waste of time my conributions to this thread has accumulated.

  29. #29
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,519


    Did you find this post helpful? Yes | No

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

    Hi,
    For what it's worth I'm not an experienced programmer but If I'm wrong I'd like to know for future use. In the few prorams I've written I've always had to use caps for the defines to work but I haven't been calling asm routines. So I'd at least try it to see if it matters.
    But you have been calling ASM routines since that is exactly what PBP does, it "builds" your code into an ASM program by "stitching together" different library routines which are all in ASM. Some of these routines have "settings" which can be "configured" and this is done with the DEFINE directive. The DEFINE directive is a PBP "command" and PBP is not case sensitive so the DeFiNe can be any case but the name of the "setting" you want to configure must match the case of how it is written in the ASM routine it "configures" - and all the PBP library routies use all upper case.

    Let's take the simple example of DEFINE OSC 20, in the library file you'll find something like (and this is ASM):
    Code:
        ifndef OSC
    OSC = 4
        endif
    See, here OSC is all upper case and since this is code that is directly used by the assembler IS case sensitive so if you, in your program, would do define osc 20 it wouldn't work. Not because define is lower case but because osc is. What happens is that the assembler creates a constant named osc (which is different from OSC that the library routines is looking for) and assignes the value 20 to it. The library routines checks if OSC has been defined but doesn't see it so it sets its value to 4 - when you intended for it to be 20.

    If you write a ASM routine where the assembler is looking for aBc then you'd need to use DEFINE aBc for it to work, define ABC wouldn't, neither would DEFINE ABC.

    Man, I really hope I got that right but if I didn't I hope someone will jump in and correct me.

    /Henrik.
    Last edited by HenrikOlsson; - 13th August 2013 at 16:13.

  30. #30
    GaryGoatley's Avatar
    GaryGoatley Guest


    Did you find this post helpful? Yes | No

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

    Every link I find about this display is coupled with Arduino and they always reference a library. I wasn't able to find any libraries written for PBP so it might never work on Basic until you can find the library for it.I honestly think you need to take a step back and go for blinking a LED. A quick review of your posts only indicate nothing is working. If you're communicating properly with the PIC the LED will indicate that.

  31. #31
    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, I blink a led and is worked normally. In other words, my main program is ok! I think this display problem is clock, I think is very fast for the TM1640 display controler. I will try with other PIC16F628A but dont have yet. But, already thank for your contribution.

    Regards,

  32. #32
    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
    '----------------------------------------------------------------

  33. #33
    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,

  34. #34
    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: 3193
Size:  611.0 KB

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


    Regards,

  35. #35
    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
    New improved code. Pauses not required. Address set command now works. If you don't write to all 16 displays some segments of displays not written to turn on when they shouldn't, therefore it is best to write to all 16 displays and over-write these segments.
    Phil

    Code:
    'PIC18F2550 @ 48mHz, USB bootloader, JY-LM1640 16 x 7 seg display
    
    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 ($00 - $0F)
        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
        PAUSE 500
        
    '---------- Start of program ------------------------------------
        FOR digit = 0 TO 4          'Scroll to right, increase brightness
            GOSUB PRINT:
        NEXT
        FOR digit = 3 TO 0 STEP -1  'Scroll to left, decrease brightness
            GOSUB PRINT:
        NEXT
        END
    '---------- Print to display ------------------------------------    
    PRINT: 
        dat = dat_com_inc           'Data command setting
        GOSUB COMMAND:
        dat = address + digit       'Set address
        din = 0 : sclk = 0          'Start transmission process    
        SHIFTOUT din,sclk,0,[dat]   'LSB first, clock idles low
        FOR n = 0 TO 15             'Print 16 characters
            LOOKUP n,[0,115,6,57,6,127,113,91,109,109,63,0,64,64,64,64],dat	
    	SHIFTOUT din,sclk,0,[dat]   'Print message
        NEXT
        sclk = 1 : din = 1          'End transmission process
        dat = dis_com_on + digit    'Set brightness
        GOSUB COMMAND:
        PAUSE 1000
        RETURN
    '----------------------------------------------------------------
    COMMAND:
        din = 0 : sclk = 0          'Start transmission process 
        SHIFTOUT din,sclk,0,[dat]   'LSB first, clock idles low
        sclk = 1 : din = 1          'End transmission process
        RETURN
    '----------------------------------------------------------------

  36. #36
    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,

    This last code is perfect!!!

    Thank you again for your attention and partnership my friend. If I can help, please contact me.

    Name:  IMG_1273.jpg
Views: 3476
Size:  326.6 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