Code:
' ================================== MAXhelp.bas =================================
' This program uses a PICAXE-08M2 to manually shift-out SPI data to
' a MAX7219 LED display driver. The 7219 is connected to a 4-digit,
' 7-segment LED display. The program displays the word "HELP"
' === Constants ===
' Hardware interface to the MAX7219
symbol sData = 0 ' data out line to Max7219
symbol clock = 1 ' clock line
symbol sLoad = 2 ' pulse briefly to load data onto LEDs
' Register addresses for the MAX7219
symbol decode = 9 ' decode register; specify digits to decode
symbol brite = 10 ' intensity (brightness) register; 15 = 100%
symbol scan = 11 ' scan-limit register; specify # of LEDs
symbol on_off = 12 ' 1 = display on; 0 = display off
' === Variables =====
symbol outByte = b0 ' data byte to be transmitted to the LED
symbol maxReg = b1 ' MAX register that receives the data byte
symbol forMax = w0 ' We're breaking a rule here! (See text)
symbol index = b2 ' used in for-next loop
' === Directives ====
'#com 3 ' specify com port
#picaxe 08M2 ' specify PICAXE processor
#terminal off ' disable terminal window
' ============================== Begin Main Program =============================
setfreq m8
dirsC = %00010111 ' set portC as outputs (except C.3, C5,6,7)
' Initialize MAX7219
maxReg = scan ' set scan limit for digits 0-3
outByte = 3
gosub shout16
maxReg = brite ' set brightness to 5 (15 = 100%)
outByte = 5
gosub shout16
maxReg = decode ' set BCD decoding for digits 0-3
outByte = 15
gosub shout16
maxReg = on_off ' turn display on
outByte = 1
gosub shout16
' Send data to the four digits
maxReg = 1 ' 1st LED from left = "H"
outByte = 12
gosub shout16
maxReg = 2 ' 2nd LED from left = "E"
outByte = 11
gosub shout16
maxReg = 3 ' 3rd LED from left = "L"
outByte = 13
gosub shout16
maxReg = 4 ' 4th LED from left = "P"
outByte = 14
gosub shout16
' ==================== End Main Program - Subroutines follow =====================
shout16:
for index = 15 to 0 step -1 ' MAX7219 requires a 16-bit word
if bit15 = 1 then ' set sdata to correspond to bit15
high sData
else
low sData
endif
pulsout clock, 2 ' briefly pulse the clock line
forMax = forMax * 2 ' shift char left for next MSB
next index
pulsout sLoad, 2 'briefly pulse the load line
return
Thanks
Jaden