Six digit TM1637 display

pxgator

Senior Member
This program only displays 0 to 9, A to F, dashes, and decimal points.
Just for fun I added a few lines to drive the display at four different speeds.
I will be working on a counting program that uses this code but The TM1637 six
digit displays are not sequential so in order to use this program as a counter
that sequences in a logical order a different sequencing command must be used.
The usual code of $C0 which works on four digit displays does not work.
The valid sequencing commands for the TM1637 are $C0 to $C5 I tried them all.
I found that $C3 sequences in a logical order but it is from right to left.

Code:
;08m2_TM1637-6_orig

#picaxe 08m2

;segment data for TM1637
;( 0 1 2 3 4 5 6 7 8 9 A b C d E F dash decimal point)
DATA 0,($3f,$06,$5b,$4f,$66,$6d,$7d,$07,$7f,$6f,$77,$7c,$39,$5e,$79,$71, $40, $80)


;for TM1637
symbol dio = C.1 ;TM1637 data pin to 08m2 leg 6
symbol clk = C.2 ;TM1637 clock pin to 08m2 leg 5
symbol DIG6 = b2
symbol DIG5 = b3 ;DIG6 to DIG1 from right to left
symbol DIG4 = b4
symbol DIG3 = b5
symbol DIG2 = b6
symbol DIG1 = b7


gosub brightness ;set display brightness

START:
inc b8
if b8 = 1 then setfreq m4 : endif
if b8 = 2 then setfreq m8 : endif   ;just for fun
if b8 = 3 then setfreq m16 : endif
if b8 = 4 then setfreq m32 : endif
if b8 = 4 then
  b8 = 0
endif

for b1 = 0 to 18 ;sequence thru all character
  DIG6 = b1 : DIG5 = b1 ;bytes stored in the data
  DIG4 = b1 : DIG3 = b1
  DIG2 = b1 : DIG1 = b1
  gosub DISPLAY
  pause 1000
next b1

;Group of subroutines to read the digits from data and output to the display
;===========================================================================

DISPLAY:
;Enable sequential movement
call i2CStart
b0 = $40
call i2CWrByte
call i2CStop

;First digit
call i2CStart
b0 = $C3        ;command to enable sequential movement from right to left
call i2CWrByte

read DIG6,b0    ;to turn on decimal point on any digit add 128 to b0
call i2CWrByte  ;DIG6 is the least significant digit

;Second digit    ;to blank any digit let b0 = 0
read DIG5,b0
call i2CWrByte

;Third digit
read DIG4,b0
call i2CWrByte

;Fourth digit
read DIG3,b0
call i2CWrByte

;Fifth digit
read DIG2,b0
call i2CWrByte

;Sixth digit
read DIG1,b0
call i2CWrByte
call i2CStop

if b1 = 18 then START
return

i2CStart:
high clk
high dio
low dio
low clk
return

i2CStop:
low clk
low dio
high clk
high dio
return

;Send a byte
;b0 contains the bits that are used here
i2CWrByte: ;outpinC.1 = dio
outpinC.1 = bit0:pulsout clk, 1
outpinC.1 = bit1:pulsout clk, 1
outpinC.1 = bit2:pulsout clk, 1
outpinC.1 = bit3:pulsout clk, 1
outpinC.1 = bit4:pulsout clk, 1
outpinC.1 = bit5:pulsout clk, 1
outpinC.1 = bit6:pulsout clk, 1
outpinC.1 = bit7:pulsout clk, 1
pulsout clk, 1
return

;Set the brightness ($80 = off, $88 to $8F are the low to high bright levels)
brightness:
call i2CStart
b0 = $8b
call i2CWrByte
call i2CStop
return

;===========================================================================
 
Last edited:
Top