'===-[ Variables ]-==========================================================
symbol head = b0 ' start of eeprom translation
symbol tail = b1 ' end of eeprom translation
symbol char = b2 ' character that the loop read
symbol charpntr = b3 ' which character are we looking at?
symbol scratchpntr = b4 ' scratchpad pointer
symbol index = b5 ' general purpose counter
symbol temp = b6 ' general temp variable
symbol messageend = b7 ' end of message scroll
symbol maxreg = b8 ' register for MAX7219
symbol maxdata = b9 ' data to send to MAX7219
'===-[ PICAXE 20X2 Pin Definitions ]-========================================
symbol SData = B.2 ' MAX7219 serial data
symbol CS = B.3 ' MAX7219 chip select
symbol CLK = B.4 ' MAX7219 serial clock
'===-[ MAX7221 Constants ]-==================================================
symbol noop = $00 ' no operation
symbol dig0 = $01 ' column 0
symbol dig1 = $02 ' column 1
symbol dig2 = $03 ' column 2
symbol dig3 = $04 ' column 3
symbol dig4 = $05 ' column 4
symbol dig5 = $06 ' column 5
symbol dig6 = $07 ' column 6
symbol dig7 = $08 ' column 7
symbol decode = $09 ' turn on/off BCD decoding (off)
symbol intensity = $0A ' brightness
symbol scan_limit = $0B ' how many digits to display
symbol shutdown = $0C ' turn off MAX7219
symbol display_test = $0F ' test
symbol display_on = $01 ' display on
symbol display_off = $00 ' display off
symbol display_test_on = $01 ' test on
symbol display_test_off = $00 ' test off
symbol display_normal = $00 ' normal operation
symbol blank = $0F ' blank display
EEPROM $90,(" THE PICAXE ROCKS",255) ' The message to display
charpntr = $90 ' start of the message data in EEPROM
scratchpntr = 3 ' scratchpad pointer starts at 3 for the data
'===-[ Setup MAX7221 ]-======================================================
' Quick setup routine for the MAX7221
Setup_MAX7221:
for index = 0 to 3
lookup index,(decode,intensity,scan_limit,shutdown),maxreg
lookup index,($00,$08,$07,display_on),maxdata
gosub SendTo_Max7221
next
pause 30
' Clear anything on the display
Clear_MAX7221:
for index = 0 to 7
lookup index,(dig0,dig1,dig2,dig3,dig4,dig5,dig6,dig7),maxreg
maxdata = $00
gosub SendTo_Max7221
next
Main:
do
read charpntr, char ' grab a character
if char = 255 then ' if char = 255 we've reached end of string
goto ScratchPadLoaded ' go display the contents
else
Convert_Character: ' this subroutine converts to EEPROM location
if char = 32 then
char = $00 ' special case for the space
else
char = char-64 * 5
endif
head = scratchpntr
tail = head + 4 ' set start and end points
Load_Scratchpad:
for index = head to tail
read char, temp ' this subroutine reads the EEPROM dada
put index, temp ' and puts the contents into scratchpad
inc char ' next column of the character
next index
inc index ' increase the counter and...
put index, $00 ' ...pad a space
scratchpntr = tail + 2 ' account for space padding
inc charpntr ' go get the next character
endif
loop
ScratchPadLoaded:
dec scratchpntr ' remove the last padded space
put 0, scratchpntr ' put the value of scratchpntr into scratchpad location 0
get 0, messageend ' load messageend with value
scratchpntr = 3
index = 0
Display_It:
do
head = scratchpntr ' set the start of column data
tail = head + 7 ' set the end of the column data
temp = 1 ' used to select column
for index = head to tail ' get 8 columns of data
get index, maxdata ' load column data into maxdata variable
maxreg = temp ' select which column
gosub SendTo_Max7221 ' we have column and data -> go display it
inc temp ' advance column pointer
next index ' next column
inc scratchpntr ' move "window" forward by 1
pause 20 ' slow down scrolling
loop while scratchpntr < messageend ' do for length of message
scratchpntr = 3 ' reset the pointer to the beginning
goto Display_It ' display the message forever
end
'===-[ Subroutines ]-========================================================
' maxreg is the digit (column) to be displayed
' maxdata is the LED pattern (1=on 0=off)
SendTo_Max7221:
low CS
shiftout CLK,SDATA,1,(maxreg,maxdata)
high CS
return
'===-[ FONT DATA ]-==========================================================
' 5x7 fonts
EEPROM $00,(%00000000,%00000000,%00000000,%00000000,%00000000) ' SPACE
'EEPROM $05,(%00111111,%01000100,%01000100,%01000100,%00111111) 'A
EEPROM $05,(%00011111,%00100100,%01000100,%00100100,%00011111) 'A - Alternate
EEPROM $0A,(%01111111,%01001001,%01001001,%01001001,%00110110) 'B
EEPROM $0F,(%00111110,%01000001,%01000001,%01000001,%00100010) 'C
EEPROM $14,(%01111111,%01000001,%01000001,%01000001,%00111110) 'D
EEPROM $19,(%01111111,%01001001,%01001001,%01001001,%01000001) 'E
EEPROM $1E,(%01111111,%01001000,%01001000,%01001000,%01000000) 'F
EEPROM $23,(%00111110,%01000001,%01001001,%01001001,%00101111) 'G
EEPROM $28,(%01111111,%00001000,%00001000,%00001000,%01111111) 'H
EEPROM $2D,(%00000000,%01000001,%01111111,%01000001,%00000000) 'I
EEPROM $32,(%00000010,%00000001,%01000001,%01111110,%01000000) 'J
EEPROM $37,(%01111111,%00001000,%00010100,%00100010,%01000001) 'K
EEPROM $3C,(%01111111,%00000001,%00000001,%00000001,%00000001) 'L
EEPROM $41,(%01111111,%00100000,%00011000,%00100000,%01111111) 'M
EEPROM $46,(%01111111,%00010000,%00001000,%00000100,%01111111) 'N
EEPROM $4B,(%00111110,%01000001,%01000001,%01000001,%00111110) 'O
EEPROM $50,(%01111111,%01001000,%01001000,%01001000,%00110000) 'P
EEPROM $55,(%00111110,%01000001,%01000101,%01000010,%00111101) 'Q
EEPROM $5A,(%01111111,%01001000,%01001100,%01001010,%00110001) 'R
;EEPROM $5F,(%00110001,%01001001,%01001001,%01001001,%01000110) 'S
EEPROM $5F,(%00110010,%01001001,%01001001,%01001001,%00100110) 'S - Alternate
EEPROM $64,(%01000000,%01000000,%01111111,%01000000,%01000000) 'T
EEPROM $69,(%01111110,%00000001,%00000001,%00000001,%01111110) 'U
EEPROM $6E,(%01111100,%00000010,%00000001,%00000010,%01111100) 'V
EEPROM $73,(%01111110,%00000001,%00001110,%00000001,%01111110) 'W
EEPROM $78,(%01100011,%00010100,%00001000,%00010100,%01100011) 'X
EEPROM $7D,(%01110000,%00001000,%00000111,%00001000,%01110000) 'Y
EEPROM $82,(%01000011,%01000101,%01001001,%01010001,%01100001) 'Z