' pin6= latch clock HC595 pin 12 - low to high transition latches the data
' pin7 = serial data out = HC595 pin 14
' pin5= shift clock = HC595 pin 11 - low to high tranition stores the serial data out
' note **** in the picaxe programmer View menue Options/Mode screen, change the 16x gosub to 256x gosub
' if get weird bugs watch the maximum 4 nested gosubs
start: pause 1000
'gosub setclock
GoSub Initialiseclock ' tell i2c that clock exists
GoTo initnew ' start display
main: ' main program loop
'gosub testcount used for debugging the time set
GoSub buttontest
GoSub Readtime
GoSub SendData ' send to output pin 3 blue wire
GoSub firstline ' put display on 1st line
peek 92, b0
GoSub splitbyte ' hours
b1 = ":"
GoSub wrchar
peek 91, b0
GoSub splitbyte ' minutes
GoSub buttontest
b1 = 136 ' move cursor
GoSub wrins
peek 94, b0
GoSub splitbyte ' day
GoSub buttontest
b1 = "/"
GoSub wrchar
peek 95, b0
GoSub splitbyte ' month
GoSub buttontest
b1 = "/"
GoSub wrchar
peek 96, b0
GoSub splitbyte ' year
GoSub buttontest
' display weekday
GoSub Readtime
GoSub secondline
peek 93, b10 ' number 1 to 7, 1=sunday
Select Case b10
Case 1
For b9 = 0 To 8
lookup b9, ("Sunday "), b1
GoSub wrchar
Next
Case 2
For b9 = 0 To 8
lookup b9, ("Monday "), b1
GoSub wrchar
Next
Case 3
For b9 = 0 To 8
lookup b9, ("Tuesday "), b1
GoSub wrchar
Next
Case 4
For b9 = 0 To 8
lookup b9, ("Wednesday"), b1
GoSub wrchar
Next
Case 5
For b9 = 0 To 8
lookup b9, ("Thursday "), b1
GoSub wrchar
Next
Case 6
For b9 = 0 To 8
lookup b9, ("Friday "), b1
GoSub wrchar
Next
Case 7
For b9 = 0 To 8
lookup b9, ("Saturday "), b1
GoSub wrchar
Next
endselect
GoSub buttontest
GoSub OffPeakPower
' spend most of time waiting for button push
w0 = 0
Do
if pin1=1 then exit
pause 100
w0 = w0 + 1
if w0>500 then exit
Loop
GoSub buttontest
GoTo main
' **** latch routines ***
senddatatolatch: ' sends data in b0
b6 = b0 ' so returns b0 unchanged
' note QA is MSB and QH is LSB (binary number reads down) feed in LSB first
low 5
low 6
low 7
For b1 = 1 To 8
b2=b0 and %00000001
If b2 = 0 Then
low 7
Else
high 7
End If
high 5
low 5
Let b0 = b0 / 2
Next
high 6
low 6
b0 = b6
poke 87, b0 ' store the latch status
Return
QAhigh: peek 87, b0 ' pin 15
b0=b0 or %10000000
GoTo senddatatolatch
QAlow: peek 87, b0 ' pin 15
b0=b0 and %01111111
GoTo senddatatolatch
QBhigh: peek 87, b0 ' pin 1
b0=b0 or %01000000
GoTo senddatatolatch
QBlow: peek 87, b0 ' pin 1
b0=b0 and %10111111
GoTo senddatatolatch
QChigh: peek 87, b0 ' pin 2
b0=b0 or %00100000
GoTo senddatatolatch
QClow: peek 87, b0 ' pin 2
b0=b0 and %11011111
GoTo senddatatolatch
QDhigh: peek 87, b0 ' pin 3
b0=b0 or %00010000
GoTo senddatatolatch
QDlow: peek 87, b0 ' pin 3
b0=b0 and %11101111
GoTo senddatatolatch
QEhigh: peek 87, b0 ' pin 4
b0=b0 or %00001000
GoTo senddatatolatch
QElow: peek 87, b0 ' pin 4
b0=b0 and %11110111
GoTo senddatatolatch
QFhigh: peek 87, b0 ' pin 5
b0=b0 or %00000100
GoTo senddatatolatch
QFlow: peek 87, b0 ' pin 5
b0=b0 and %11111011
GoTo senddatatolatch
QGhigh: peek 87, b0 ' pin 6
b0=b0 or %00000010
GoTo senddatatolatch
QGlow: peek 87, b0 ' pin 6
b0=b0 and %11111101
GoTo senddatatolatch
QHhigh: peek 87, b0 ' pin 7
b0=b0 or %00000001
GoTo senddatatolatch
QHlow: peek 87, b0 ' pin 7
b0=b0 and %11111110
GoTo senddatatolatch
' *** clock routines ***
Readtime:
i2cslave %11010000, i2cslow, i2cbyte ‘ set slave details
readi2c 0, (b0, b1, b2,b3,b4,b5,b6) ‘ read sec, min, hour weekday day month year
poke 90, b0 ' secs
poke 91, b1 ' mins
poke 92, b2 ' hours
poke 93, b3 ' weekday 1-7
poke 94, b4 ' day
poke 95, b5 ' month
poke 96, b6 ' year
b13 = b0
GoSub BCDtoDecimal ' seconds
b0 = b13
b13 = b1
GoSub BCDtoDecimal ' mins
b1 = b13
b13 = b2
GoSub BCDtoDecimal ' hours
b2 = b13
b13 = b4
GoSub BCDtoDecimal ' day (no need to do weekday as <10)
b4 = b13
b13 = b5
GoSub BCDtoDecimal ' month
b5 = b13
b13 = b6
GoSub BCDtoDecimal
b6 = b13
poke 80, b0 ' poke decimal data for exporting to other picaxes if requested
poke 81, b1 ' mins
poke 82, b2 ' hour
poke 83, b3 ' day 1-7
poke 84, b4 ' day
poke 85, b5 ' month
poke 86, b6 ' year
Return
Setclock:i2cslave %11010000, i2cslow, i2cbyte
' seconds minutes hours weekday day month year
' sunday = 1 and this was set on Wed = 4
' day of the week number is not linked - it just goes to 7 then resets
' see codes re 24/12 hour clock but essentially if send as the hex number is 24h clock
' *** warning if ever set clock use 2 bcd numbers not decimal value
writei2c 0, ($00, $32, $13, $01, $05, $08, $07, $10)
Return
WriteClock:i2cslave %11010000, i2cslow, i2cbyte' pokes last reads back into clock
peek 90, b0
peek 91, b1
peek 92, b2
peek 93, b3
peek 94, b4
peek 95, b5
peek 96, b6
writei2c 0,(b0,b1,b2,b3,b4,b5,b6,$10)
Return
Initialiseclock:i2cslave %11010000, i2cslow, i2cbyte
Return
BCDtoDecimal: ' all clock values are 2 bcd numbers. If convert to hex they display correctly
' pass b13, returns b13
b12=b13 and %00001111
b11 = b13 / 16 ' shifts right 4 places
b10 = b11 * 10
b13 = b10 + b12
Return
' ***** LCD routines ******
' pin7 for reved's direct comms = pin 14 on the display = QA
' pin6= display 13 = QB
' pin5 = display 12 = QC
' pin4 = display 11 = QD
' pin3 = display 6 = QE
' pin2 = display 4 = QF
' QG = led
initnew: b0 = 0
GoSub senddatatolatch ' all outputs low
pause 200
GoSub QChigh ' send 0011
GoSub QDhigh
GoSub toggleenable
pause 10
GoSub toggleenable
GoSub toggleenable
GoSub QDlow ' send 0010
GoSub toggleenable
GoSub toggleenable
GoSub QAhigh ' send 1000
GoSub QClow
GoSub toggleenable
b1=%00001110' 14
GoSub wrins
GoSub cleardisplay
GoSub hidecursor
GoSub firstline
GoTo main
cleardisplay: b1 = 1
GoSub wrins
Return
hidecursor: b1 = 12
GoSub wrins
Return
firstline: b1 = 128
GoSub wrins
Return
secondline: b1 = 192
GoSub wrins
Return