; *******************************
; ***** Sample Header File *****
; *******************************
; Filename: DOT MATRIX DISPLAY
; Date: 21/04/2010
; File Version:
; Written by:
; Function:
; Last Revision:
; Target PICAXE:
; *******************************
#PICAXE 20x2
SETFREQ M64
#No_Table
#No_Data
EEPROM 0, (" PICAXE ") '7
'EEPROM 8, ("MONDAYTUESDAYWEDNESDAYTHURSDAYFRIDAYSATURDAYSUNDAY")' 57
EEPROM 58,("JANFEBMARAPRMAY")
Symbol CharPointer =W4
Symbol TempByte1 =B12
Symbol TempByte2 =B11
Symbol Get_ =B13
Symbol DigitToDisplay=B14
Symbol Digit =B15
Symbol RowNumber =B16
Symbol Latch = B.3 'Columns Latch
Symbol SrClk = B.2 'Serial Data Clock
Symbol SrData = B.1 'Serial Data PIN
Symbol SrClr = C.7 'Serial Data Clear
Let DIRSC=%00000111 'Make Port C OUTPUTS
Initialize:
For b0= 0 to 56 'Initialize array by writing 1 to all locations in scratchpad
Put b0,$FF
Next b0
GOSUB Logo 'Display the word PICAXE
DisplayTime:
Colon: 'Display the two colon separators for the time.
GET_=0
TempByte1 =5 'Update Digit 5
FOR TempByte2=0 TO 1 'Repeat twice (for the two colons)
CharPointer=406 '406= 'COLON' character pointer in eeprom
DO '
PTR=Get_*8+TempByte1 'Calculate array index n*8 (this is for 8 characters)
I2cslave %10100000, i2cslow, i2cword 'Read character from the 24C512
Hi2cin CharPointer,(@ptr) 'and update scratchpad array.
Inc CharPointer
Inc get_
Loop until get_=7
TempByte1=2 ' Now Update Digit 2
GET_=0
NEXT TempByte2
'NOW READ THE TIME AND DISPLAY IT
For TempByte2 = 1 to 50 ' Duration of current time on display
'
I2cslave %11010000, i2cslow_64, i2cbyte 'Initialize Clock
Hi2cin 0,(b44,b45,b46) 'Read time
DigitToDisplay=b44 and $0F 'SECONDS UNITS
Digit=7
GOSUB UpdateDigit
GOSUB RefreshDisplay
DigitToDisplay=b44/16 'SECONDS tens
Digit=6
GOSUB UpdateDigit
GOSUB RefreshDisplay
DigitToDisplay=b45 and $0F 'MINUTES UNITS
Digit=4
GOSUB UpdateDigit
GOSUB RefreshDisplay
DigitToDisplay=b45/16 'MINUTES TENS
Digit=3
GOSUB UpdateDigit
GOSUB RefreshDisplay
DigitToDisplay=b46 and $0F 'HOURS UNITS
DIGIT=1
GOSUB UpdateDigit
GOSUB RefreshDisplay
DigitToDisplay=b46/16 'HOURS TENS
IF DigitToDisplay=0 then 'BLANK LEADING ZERO
DigitToDisplay=32 'ASCII SPACE dec number
ENDIF
Digit=0
GOSUB UpdateDigit
GOSUB RefreshDisplay
Next TempByte2
Gosub displaydate 'Display the date and month
GOSUB Logo 'Display logo again
GOTO DisplayTime 'Repeat
UpdateDigit:
CharPointer=DigitToDisplay*7 'Fetch character in eeprom and get data
GET_=0
DO
PTR=Get_*8+Digit 'Calculate array index n*8 (this is for 8 characters)
I2cslave %10100000, i2cslow, i2cword
hi2cin CharPointer,(@ptr)
Inc CharPointer
Inc get_
Loop until get_=7
RETURN
DisplayDate:
I2cslave %11010000, i2cslow_64, i2cbyte
Hi2cin 3,(b44,b45,b46) 'Read DAY,DATE,MONTH
DigitToDisplay=32 'ASCII dec value for SPACE
Digit=0
GOSUB UpdateDigit
DigitToDisplay=b45/16 ;DAY TENS
Digit=1
GOSUB UpdateDigit
DigitToDisplay=b45 and $0F 'DAY UNITS
Digit=2
GOSUB UpdateDigit
DigitToDisplay=32 'ASCII SPACE
Digit=3
GOSUB UpdateDigit
Select Case b46 ' Show month in letters. 'May' only up to now
Case 5
DIGIT=4
FOR TempByte1 = 70 TO 72
READ TempByte1,DigitToDisplay
GOSUB UpdateDigit
INC DIGIT
NEXT
Endselect
DigitToDisplay=32 'ASCII dec value for SPACE
Digit=7
GOSUB UpdateDigit
FOR TempByte2= 1 TO 200 'Duration of display showning date
GOSUB RefreshDisplay
NEXT TempByte2
RETURN
Logo: ' Get data for the logo, in this case 'PICAXE'
DIGIT=0
FOR TempByte1 = 0 TO 7
READ TempByte1,DigitToDisplay
GOSUB UpdateDigit
INC DIGIT
NEXT
FOR TempByte2= 0 TO 200 ' Duration displaying logo
GOSUB RefreshDisplay ' Refresh the entire display
NEXT TempByte2
RETURN
RefreshDisplay: '
RowNumber=0
DO
Ptr=RowNumber*8 'Goto scratchpad array
Shiftout SrClk,SrData,msbfirst,(@PTRINC/5,@PTRINC/5,@PTRINC/5,@PTRINC/5,@PTRINC/5,@PTRINC/5,@PTRINC/5,@PTR/5)
Pulsout latch,1
Pinsc=RowNumber
Pause 4 'Delay
Pinsc=%111 'Switch off rows
Inc RowNumber
Loop until RowNumber=7
RETURN