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
'----------------------------------------------------------------
Bookmarks