The commented code is below. Times were worked out empirically and are accurate to within a couple of seconds. The main loop is simply a 5 second pause at 31KHz. This is preferable to nap because response to an interrupt, waking the timer, is instantaneous. Upon wake the clock frequency is increased to 4 MHz. Single clicks of the switch (by pushing on the face with the six LEDs) increment the time interval with the number of lit LEDs indicating the time. If the device is then left unclicked for a few seconds, countdown begins from the indicated number of minutes. The LEDs flash to indicate the remaining time on the clock; at the end of the time the device flashes and beeps pleasantly, and then returns to low clock frequency sleep mode. The device can be interrupted during the countdown or the alarm, with another single click.
EEPROM
0,(3)
init:
disableBOD
pinsC=000000
setint
001000,001000
setfreq
k31
main:
pause
5000
goto
main
interrupt:
setfreq
m4
let
dirsC=%11110111
settime:
'clicks
start at an initial default of 3 min, go up to six and back around to 1
'after the first time use the last value stored in eeprom
read
0, b4
select
case b4
case
1
goto onestart
case
2
goto twostart
case
3
goto threesstart
case
4
goto fourstart
case
5
goto fivestart
case
6
goto sixesstart
endselect
threesstart:
if
pinC.3=1 then threesstart
b10=0
b1=3
threes:
gosub
three
if
pinC.3=1 then fourstart
b10=b10+1
if
b10>40 then goto countdown3
goto
threes
fourstart:
if
pinC.3=1 then fourstart
b10=0
b1=4
fours:
gosub
four
if
pinC.3=1 then fivestart
b10=b10+1
if
b10>40 then goto countdown4
goto
fours
fivestart:
if
pinC.3=1 then fivestart
b10=0
b1=5
fives:
gosub
five
if
pinC.3=1 then sixesstart
b10=b10+1
if
b10>40 then goto countdown5
goto
fives
sixesstart:
if
pinC.3=1 then sixesstart
b10=0
b1=6
sixes:
gosub
six
if
pinC.3=1 then onestart
b10=b10+1
if
b10>40 then goto countdown6
goto
sixes
onestart:
if
pinC.3=1 then onestart
b10=0
b1=1
ones:
gosub
one
if
pinC.3=1 then twostart
b10=b10+1
if
b10>40 then goto countdown1
goto
ones
twostart:
if
pinC.3=1 then twostart
b10=0
b1=2
twos:
gosub
two
if
pinC.3=1 then threesstart
b10=b10+1
if
b10>40 then goto countdown2
goto
twos
countdown6:
if
b1 !=b4 then write 0,b1
endif
pinsC=000000
for
b3=0 to 29
pause
1970
if
pinC.3=1 then backtobed
gosub
six
next
b3
countdown5:
if
b1 !=b4 then write 0,b1
endif
pinsC=000000
for
b3=0 to 29
pause
1970
if
pinC.3=1 then backtobed
gosub
five
next
b3
countdown4:
if
b1 !=b4 then write 0,b1
endif
pinsC=000000
for
b3=0 to 29
pause
1970
if
pinC.3=1 then backtobed
gosub
four
next
b3
countdown3:
if
b1 !=b4 then write 0,b1
endif
pinsC=000000
for
b3=0 to 29
pause
1970
if
pinC.3=1 then backtobed
gosub
three
next
b3
countdown2:
if
b1 !=b4 then write 0,b1
endif
pinsC=000000
for
b3=0 to 29
pause
1970
if
pinC.3=1 then backtobed
gosub
two
next
b3
countdown1:
if
b1 !=b4 then write 0,b1
endif
pinsC=000000
for
b3=0 to 58
pause
970
if
pinC.3=1 then backtobed
gosub
one
next
b3
alarm:
for
b3=0 to 50
tune
C.2, 1,($00,$03, $05)
pinsC=000111
if
pinC.3=1 then backtobed
tune
C.2, 1,($07,$09, $11)
pinsC=010000
if
pinC.3=1 then backtobed
next
b3
backtobed:
pinsC=010000
if
pinC.3=1 then backtobed
setint
001000,001000
setfreq
k31
pinsC=000000
return
'at
k31, disablebod
'pause
5000 this config gives 3mv across a 200ohm inline supply resistor
'nap
4 gives 2.8 mv
'at
m4 , disablebod
'nap
4 gives 2.8 mv
'pause
5000 gives 110mv!!
'at
m4 , enablebod
'nap
4 gives 4.8 mv
'pause
5000 gives 110mv!!
'at
k31 , enablebod
'nap
4 gives 3.8 mv
'pause
5000 gives 4 mv
six:
let
pinsC=00000001
pause
5
let
pinsC=00010110
pause
5
let
pinsC=00000010
pause
5
let
pinsC=00010101
pause
5
let
pinsC=00000100
pause
5
let
pinsC=00010011
pause
5
let
pinsC=00000000
return
five:
let
pinsC=00000000
pause
5
let
pinsC=00010110
pause
5
let
pinsC=00000010
pause
5
let
pinsC=00010101
pause
5
let
pinsC=00000100
pause
5
let
pinsC=00010011
pause
5
let
pinsC=00000000
return
four:
let
pinsC=00000000
pause
5
let
pinsC=00000000
pause
5
let
pinsC=00000010
pause
5
let
pinsC=00010101
pause
5
let
pinsC=00000100
pause
5
let
pinsC=00010011
pause
5
let
pinsC=00000000
return
three:
let
pinsC=00000000
pause
5
let
pinsC=00000000
pause
5
let
pinsC=00000000
pause
5
let
pinsC=00010101
pause
5
let
pinsC=00000100
pause
5
let
pinsC=00010011
pause
5
let
pinsC=00000000
return
two:
let
pinsC=00000000
pause
5
let
pinsC=00000000
pause
5
let
pinsC=00000000
pause
5
let
pinsC=00000000
pause
5
let
pinsC=00000100
pause
5
let
pinsC=00010011
pause
5
let
pinsC=00000000
return
one:
let
pinsC=00000000
pause
5
let
pinsC=00000000
pause
5
let
pinsC=00000000
pause
5
let
pinsC=00000000
pause
5
let
pinsC=00000000
pause
5
let
pinsC=00010011
pause
5
let
pinsC=00000000
return


No comments:
Post a Comment