' === LED47Driver.bas ========= 2010.04.21 ========== Ron Hackett === ' Program runs on a PICAXE-08M & controls a MAX7219 LED display ' driver, which is connected to a 4-digit, 7-segment LED display. ' Program serially receives a 4-digit number & displays it on LEDs ' === Constants === symbol fromMP = 3 ' serial input is received on input3 symbol blank = 15 ' used by MAX7219 to blank a digit ' Hardware interface to the MAX7219 symbol maxclok = 4 ' data is valid on rising edge of the clock pin symbol maxdata = 1 ' data bits are shifted out this pin to MAX7219 symbol maxload = 2 ' 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 char1 = b3 ' 1st character (from left) to display symbol char2 = b4 ' 2nd character (from left) to display symbol char3 = b5 ' 3rd character (from left) to display symbol char4 = b6 ' 4th character (from left) to display ' === Directives === #com 3 ' 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 = 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 = %00001111 gosub shout16 maxreg = on_off ' turn display on outbyte = 1 gosub shout16 maxreg = 1 ' initialize display to all blank outbyte = blank gosub shout16 maxreg = 2 outbyte = blank gosub shout16 maxreg = 3 outbyte = blank gosub shout16 maxreg = 4 outbyte = blank gosub shout16 do ' get 4 digits and display them on LEDs serin fromMP, N4800_8,char1,char2,char3,char4 maxreg = 1 ' 1st LED from left outbyte = char1 gosub shout16 maxreg = 2 ' 2nd LED from left outbyte = char2 gosub shout16 maxreg = 3 ' 3rd LED from left outbyte = char3 gosub shout16 maxreg = 4 ' 4th LED from left outbyte = char4 gosub shout16 loop ' =========== End Main Program - Subroutines Follow ============== shout16: ' Shift out 16-bit data word to (MSB first) ===== 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