Write SPIN code for TM1637 and TM1638 (Part III)

big-banging seven-segment driver chips

One of the other inexpensive TM1638 modules is called QYF-TM1638 (shown on the right below). It has 16 push buttons, which is probably good enough for making your own special function calculator.

Image for post
Image for post
Propeller connection with QYF module
CON
_clkmode = xtal1 + pll16x
_xinfreq = 5_000_000
CON
DIO_PIN = 26
CLK_PIN = 25
STB_PIN = 24
VAR
byte DIN[4]


PUB main | Index
dira[DIO_PIN] := 1
dira[CLK_PIN] := 1
dira[STB_PIN] := 1
outa[STB_PIN] := 1
outa[CLK_PIN] := 1
repeat
start
send_byte($42)
delay
repeat Index from 0 to 3
read_byte(@DIN[Index])
end

waitcnt(clkfreq/10 + cnt)
PRI send_byte(data_byte) 'lsb first
repeat 8
outa[CLK_PIN] := 0
delay
outa[DIO_PIN] := data_byte & $01
data_byte >>= 1
outa[CLK_PIN] := 1
delay
PRI read_byte(data_byte_addr) | tmp
tmp := 0
dira[DIO_PIN]~
repeat 8
tmp <<= 1
outa[CLK_PIN] := 0
delay
outa[CLK_PIN] := 1
tmp := tmp | ina[DIO_PIN]
delay

byte[data_byte_addr] := tmp >< 8
dira[DIO_PIN]~~

PRI start
outa[STB_PIN]:= 0
delay
PRI end
outa[STB_PIN] := 1
delay
PRI delay '10us
waitcnt(clkfreq/100_000 + cnt)
Image for post
Image for post
TM1638 4-byte key scan table
Image for post
Image for post
Image for post
Image for post
common cathode
start
send_byte($c0)
send_byte($ff)
end
Image for post
Image for post
common anode
CON
_clkmode = xtal1 + pll16x 'Standard clock mode * crystal frequency = 80 MHz
_xinfreq = 5_000_000
CON
DIO_PIN = 26
CLK_PIN = 25
STB_PIN = 24
PUB main dira[DIO_PIN] := 1
dira[CLK_PIN] := 1
dira[STB_PIN] := 1
outa[STB_PIN] := 1
outa[CLK_PIN] := 1
start
send_byte($8f) 'turn on
end

start
send_byte($40) 'write to register
end

start 'clear
send_byte($c0)
repeat 16
send_byte($00)
end
start
send_byte($c0)
send_byte($ff)
send_byte($00)
send_byte($ff)
send_byte($00)
send_byte($ff)
send_byte($00)
send_byte($ff)
send_byte($00)
send_byte($ff)
send_byte($00)
send_byte($ff)
send_byte($00)
send_byte($ff)
send_byte($00)
send_byte($ff)
send_byte($00)
end


repeat
PRI send_byte(data_byte)
'lsb first
repeat 8
outa[CLK_PIN] := 0
delay
outa[DIO_PIN] := data_byte & $01
data_byte >>= 1
outa[CLK_PIN] := 1
delay


PRI start
outa[STB_PIN]:= 0
delay
PRI end
outa[STB_PIN] := 1
delay
PRI delay '10us
waitcnt(clkfreq/100_000 + cnt)

Summary

Seven segment display modules are quite useful for hobby electronics projects.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store