Buzby
Senior Member
I needed a 6-digit display for a project. There are some TM1637 examples in this forum, but they all seem to be for 4-digit displays.
The one I chose still uses the TM1637 chip, but this time with 6 digits. The display is available in all the usual places.
The one I got is labelled 'DM DIY MODE' as the manufacturer.
One quirk of this particular display is that the physical digit positions don't follow the logical order !.
The left three digits are swapped with the right three, and each group of three is numbered right to left.
This layout means the six digits are in the order '321654'
This might not be the same for a different manufacturer.
The code below was written for a 28X2, but it should be easily changed to work on most PICAXE chips that have enough pins.
The one I chose still uses the TM1637 chip, but this time with 6 digits. The display is available in all the usual places.
The one I got is labelled 'DM DIY MODE' as the manufacturer.
One quirk of this particular display is that the physical digit positions don't follow the logical order !.
The left three digits are swapped with the right three, and each group of three is numbered right to left.
This layout means the six digits are in the order '321654'
This might not be the same for a different manufacturer.
The code below was written for a 28X2, but it should be easily changed to work on most PICAXE chips that have enough pins.
Code:
' TM1637 6-digit 7-seg display
'=============================
#no_data
#no_table
'Symbols
'-------
symbol clk = C.6 ' Clock pin
symbol dio = C.7 ' Data pin
symbol diopin = pinC.7 ' Data pin name
symbol BrightVal = b47
symbol ByteRAW = b48
symbol ByteOut = b49
symbol Digit1 = b50
symbol Digit2 = b51
symbol Digit3 = b52
symbol Digit4 = b53
symbol Digit5 = b54
symbol Digit6 = b55
' Code starts here
'-----------------
sertxd ( ppp_filename, cr, lf ) ' My identity.
' Allow time for TM1637 startup
pause 100
BrightVal = $80 ' Display off, prevents random stuff.
gosub SetBright
pause 2000
BrightVal = $88 : gosub SetBright ' Set dim brightness
goto D1:
D1:
' Demo 123456
Digit1=1 ' Digit values, left to right
Digit2=2 ' 0 to 9 displays 0-9
Digit3=3
Digit4=4
Digit5=5
Digit6=6
gosub Display6dig ' Call the display subroutine
BrightVal = $88 : gosub SetBright ' Set dim brightness
pause 2000
D2:
' Demo ABCDEF
b50 = 10 ' Digit values, left to right
b51 = 11 ' 10 to 15 displays A-F
b52 = 12
b53 = 13
b54 = 14
b55 = 15
gosub Display6dig ' Call the display subroutine
pause 2000
D3:
' Demo indirect, and dp
for bptr = 50 to 55
b0 = bptr - 49 ' Make values 1-6
if bit0 = 0 then : b0 = b0 + 128 : endif ' 2,4,6 with dp
poke bptr, b0
next
gosub Display6dig ' Call the display subroutine
pause 2000
D4:
' Demo brightness
for b5 = 0 to 3
for b4 = $88 to $8F
brightval = b4
gosub SetBright
pause 100
next
for b4 = $8F to $88 step -1
brightval = b4
gosub SetBright
pause 100
next b4
next b5
D5:
' Demo on/off
for b4 = 0 to 15
BrightVal = $80 ' off
gosub SetBright
pause 100
BrightVal = $88 'on, min brightness
gosub SetBright
pause 100
BrightVal = $8F 'on, full brightness
gosub SetBright
pause 100
next
pause 2000
D6:
' Demo End
Digit1=17
Digit2=17
Digit3=14
Digit4=19
Digit5=13
Digit6=17
gosub Display6dig ' Call the display subroutine
pause 2000
' Display off
BrightVal = $80
gosub SetBright
end
' =============================================================
' Subroutines
'Translate to 7 seg
'------------------
T7Seg:
bit0 = 0
if ByteRAW > 127 then ' Detect dp
ByteRAW = ByteRAW - 128
bit0 = 1 ' Remember required dp
endif
select case ByteRAW ' 0-15
case 0 ByteOut = $3f '0
case 1 ByteOut = $06 '1
case 2 ByteOut = $5b '2
case 3 ByteOut = $4f '3
case 4 ByteOut = $66 '4
case 5 ByteOut = $6d '5
case 6 ByteOut = $7d '6
case 7 ByteOut = $07 '7
case 8 ByteOut = $7f '8
case 9 ByteOut = $6f '9
case 10 ByteOut = $77 'A
case 11 ByteOut = $7c 'B
case 12 ByteOut = $39 'C
case 13 ByteOut = $5e 'D
case 14 ByteOut = $79 'E
case 15 ByteOut = $71 'F
case 16 ByteOut = $3E 'U
case 17 ByteOut = $00 ' Blank
case 18 ByteOut = $40 ' Dash
case 19 ByteOut = $54 'n
endselect
' Add dp
if bit0 = 1 then : ByteOut = ByteOut + 128 : endif
return
'Send byte
'---------
SendByte:
b0 = ByteOut : diopin = bit0 : pulsout clk, 1 ' seg a
b0 = b0 / 2 : diopin = bit0 : pulsout clk, 1 ' seg b
b0 = b0 / 2 : diopin = bit0 : pulsout clk, 1 ' seg c
b0 = b0 / 2 : diopin = bit0 : pulsout clk, 1 ' seg d
b0 = b0 / 2 : diopin = bit0 : pulsout clk, 1 ' seg e
b0 = b0 / 2 : diopin = bit0 : pulsout clk, 1 ' seg f
b0 = b0 / 2 : diopin = bit0 : pulsout clk, 1 ' seg g
b0 = b0 / 2 : diopin = bit0 : pulsout clk, 1 ' dp
pulsout clk, 1 ' End byte
return
'Drive the display
'-----------------
display6dig:
'Send RAM start address
gosub StartSeq
ByteOut = $c0
gosub SendByte
' ----------------------------------------------------
' NOTE : Physical digits are not in logical order !!!!
'-----------------------------------------------------
'1st digit ( Left )
ByteRAW = Digit3
gosub T7Seg
gosub SendByte
'2nd digit
ByteRAW = Digit2
gosub T7Seg
gosub SendByte
'3rd digit
ByteRAW = Digit1
gosub T7Seg
gosub SendByte
'4th digit
ByteRAW = Digit6
gosub T7Seg
gosub SendByte
'5th digit
ByteRAW = Digit5
gosub T7Seg
gosub SendByte
'6th digit ( Right )
ByteRAW = Digit4
gosub T7Seg
gosub SendByte
gosub StopSeq
return
' Start comms sequence
'---------------------
StartSeq:
high clk
high dio
low dio
low clk
return
' Stop comms sequence
'--------------------
StopSeq:
low clk
low dio
high clk
high dio
return
'Set the brightness
'------------------
'Bit 7 high, Bit 6,5,4 low, bit 3 = display on/off, bright = bits 2,1,0
SetBright:
BrightVal = BrightVal AND $8F OR $80
gosub StartSeq
ByteOut = BrightVal
gosub SendByte
gosub StopSeq
return