Parallax, Inc. • BS2p “Plus Pack” (#45184) • 10/2001
Page 24
' -----[ Main Code ]------------------------------------------------------------
'
Main:
DEBUG CLS, "The clock is running..."
LCDCMD LCDpin, ClrLCD
Show_Clock:
GOSUB Get_Time_And_Day
LCDOUT LCDpin,Line1,[DEC2 hours,":",DEC2 minutes,":",DEC2 seconds]
LCDCMD LCDpin, (Line2 + 7)
GOSUB Print_Day
GOTO Show_Clock
' -----[ Subroutines ]----------------------------------------------------------
'
Put_Register:
I2COUT I2Cpin,Wr8583,regAddr,[regData] ' send data to register
RETURN
Get_Register:
I2CIN I2Cpin,Rd8583,regAddr,[regData] ' get data from register
RETURN
Put_Raw_Clock: ' set with rawTime
minutes = rawTime // 60
hours = rawTime / 60
Put_Clock:
regSecs = 0
regMins.HighNib = minutes / 10 ' convert regs to BCD
regMins.LowNib = minutes // 10
regHrs.HighNib = hours / 10
regHrs.LowNib = hours // 10
regMoDay.HighNib = month / 10
regMoDay.LowNib = month // 10
regMoDay = regMoDay | (day << 5) ' pack weekday in
I2COUT I2Cpin,Wr8583,2,[STR regSecs\5] ' write time & day
RETURN
Get_Time_And_Day:
I2CIN I2Cpin,Rd8583,0,[STR regCtrl \7]
' convert from BCD
seconds = (regSecs.HighNib * 10) + regSecs.LowNib
minutes = (regMins.HighNib * 10) + regMins.LowNib
hours = (regHrs.HighNib * 10) + regHrs.LowNib
rawTime = (hours * 60) + minutes
day = regMoDay >> 5
RETURN
Print_Day:
LOOKUP day,[Su,Mo,Tu,We,Th,Fr,Sa],eeAddr ' point to EE string
Print_Loop:
READ eeAddr,char ' read a character
IF (char = 0) THEN Print_Done ' done?