Updated code.
Demo code supports 0-F characters but shows the methods to display any character.
Based on Ron Hacketts good work.
Demo code supports 0-F characters but shows the methods to display any character.
Based on Ron Hacketts good work.
Code:
' === LED7219_0_F.bas ============= 2012.02.19 ============= Ron Hackett ===
' Updated by Evan Venn to support 0-F chars and lookup table and corrected use of reserved word.
' This program runs on a PICAXE-08M & controls a MAX7219 LED display driver.
' The MAX7219 is connected to a 2-digit, 7-segment LED display. Can support upto 4 LED devices.
' The program displays the word 0 thru 9, the program can easily support 0-F hex.
' === Constants ===
' Hardware interface to the MAX7219
symbol maxclok = 4 ' data is valid on the rising edge of the clock pin
symbol maxdata = 1 ' data bits are shifted out this pin to the MAX7219
symbol maxload = 2 ' briefly pulse this output to transfer data to 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 how many digits
symbol on_off = 12 ' 1 = display on; 0 = display off
' === Variables ===
symbol outword = w0 ' concatenation of maxreg and outbyte
symbol outbyte = b0 ' data to be transmitted to the MAX7219
symbol maxreg = b1 ' MAX7219 register that receives data
symbol index = b2 ' used in subroutine for...next loop
symbol bcount = b12
symbol ccount = b13
' === Directives ===
#com5 ' specify the com port
#picaxe 08m ' specify the PICAXE processor
' === Begin Main Program ==================================================
setfreq m8
' Initialize the MAX7219
maxreg = scan ' set scan limit for digits 0-3
outbyte = 1
gosub shoutbb
maxreg = brite ' set brightness to 5 (15 = 100%)
outbyte = 15
gosub shoutbb
maxreg = decode ' set BCD decoding for digits 0-3
outbyte = %00000000 ' set for No-decode mode
gosub shoutbb
maxreg = on_off ' turn display on
outbyte = 1
gosub shoutbb
rep:
for bcount = 0 to 9
for ccount = 0 to 9
' Send data to the two digits in the array
maxreg = 1 ' 1st LED (from left)
' read segment value from EEPROM
read ccount, outbyte
gosub shoutbb
maxreg = 2 ' 2nd LED (from left)
' read segment value from EEPROM
read bcount, outbyte
' add DP if required
' outbyte = outbyte + 128
gosub shoutbb
pause 15
next
next
goto rep
end
' === End Main Program - Subroutines Follow ===============================
' ===== shoutbb Subroutine ==================================================
' Shift out the 16-bit data word to the MAX7219 (MSB first)
shoutbb:
for index = 1 to 16 ' MAX7219 specifies a 16-bit word
if bit15 = 1 then ' set sdata to correspond to bit15
high maxdata
else
low maxdata
endif
pulsout maxclok,1 ' pulse clock line
outword = outword * 2 ' shift outword left for next MSB
next index
pulsout maxload,1 ' load the data word into MAX7219
return
' See the MAX7219 data sheet - Table 6. No-Decode Mode Data Bits and Corresponding Segment Lines
' this the data for the characters to be displayed. 0-F hex or you can simply use 0-9
EEPROM 0, (0x7e,0x30, 0x6d, 0x79, 0x33, 0x5b, 0x5f, 0x70, 0x7f, 0x7b, 0x77, 0x1f, 0x4e, 0x3d, 0x4f, 0x47 )