'Countdown timer using PICAXE-18X and SOMO-14D sound recorder chip
'Kevin Goom, September 7 2008
'PICAXE-18X connections are:
' Leg 1 (In2) Hold/Race switch (10K to ground, switch to 5V)
' Leg 2 (Serial out) NC
' Leg 3 (Serial in) Tie to ground through 10K resistor
' Leg 4 (Reset) Tie to +5V through 4.7K, switch to ground
' Leg 5 (Ground) Negative of battery
' Leg 6 (Out0) Bi-color status LED through 310 ohm resistor
' Leg 7 (Out1) NC
' Leg 8 (Out2) NC
' Leg 9 (Out3) NC
' Leg 10(Out4) Leg 4 (DATA) of SOMO-14D
' Leg 11(Out5) Leg 3 (CLK) of SOMO-14D
' Leg 12(Out6) NC (but used as dummy pause/pulse output)
' Leg 13(Out7) NC
' Leg 14(V+) +5V
' Leg 15(In6) Tie to ground (or +5V)
' Leg 16(In7) BUSY output from SOMO-14D
' Leg 17(In0) Countdown time select
' Leg 18(In1) Run/Pause (10K to ground, switch to 5V)
symbol Dat=W0 'Data to send to SOMO-14D
symbol CD_Time=b2 'Countdown time
symbol Status=b3 '1 = Running 0 = Paused
symbol One_Sec=1000 'Nominal 1 second. Adjust to get accurate timing
symbol Hold_Race=b6 'High = Race, Low = Hold
symbol Temp=b7
symbol Pout=20 'Set clock pulse to 200us (at 4MHz)
symbol Pout_start=200 'Set start/stop clock pulse to 2ms (at 4MHz)
#Picaxe 18X
'setfreq m8
setint %00000000,%00000000 'Clear the interrupt initially
high 5 'Make sure clock line is high initially (idles high)
Status=0 'Set "Status" to Pause
Dat=$FFFF '=%1111111111110111, stop SOMO-14D on startup or reset
gosub Send_Data1
Dat=$FFF7 '=%1111111111110111, set volume to max
gosub Send_Data1
Dat=1 'Play "Countdown Timer Ready", file 0001.ad4, on startup or reset
gosub Send_Data1
pause One_Sec
pause One_Sec
Begin:
setint %00000000,%00000000 'Clear the interrupt
Status=0 'Set "Status" to Pause
low 0 'Pause indicator LED on
loop0:
if pin1=0 then loop0 'Wait for "Start" signal
high 0 'Status indicator high (run LED lit)
Status =1 'Set "Status" to Run
pause 1000 'Pause to avoid immediate interrupt
setint %00000010,%00000010 'Set interrupt to look for Start/Resume/Reset button press
readadc 0,CD_Time 'Read countdown time (1, 2, 3, 4, or 5 minutes)
if pin2=1 then
Dat=2 'Play "Prepare to Start"
gosub Send_Data1
pause One_Sec
pause One_Sec
for b12=1 to 10 'Tick 10 times
Dat=3
gosub Send_Data1
pause One_Sec
next b12
endif
goto begin
Send_Data1:
low 5
pulsout 6,Pout_start 'Pause 2ms by pulsing dummy pin (needs >2ms low start clock level)
for Temp=1 to 15 'Loop through first 15 bits
outpin4=bit15 'Set data to MSB
pulsout 5,Pout 'Clock high for 200us to latch data on pin1
pulsout 6,Pout 'Pause 200us by pulsing dummy pin (low clock)
Dat=Dat*2 'Shift left to get next significant bit
next Temp
outpin4=bit15 'Set last data bit
high 5 'Clock idles high after last bit sent
pulsout 6,Pout_start 'Pause 2ms by pulsing dummy pin (needs >2ms high stop clock level)
Return
Send_Data2:
low 5 'Set clock line low
pulsout 6,Pout_Start 'Pause 2ms by pulsing dummy pin (needs >2ms low start clock pulse)
for Temp=1 to 8 'Loop through 8 bits of b1
outpin4=bit15 'Set data to MSB
pulsout 5,Pout 'Clock high for 200us to latch data on pin1
pulsout 6,Pout 'Pause 200us by pulsing dummy pin (low clock)
b1=b1*2 'Shift left
next Temp
for Temp=1 to 8 'Loop through 8 bits of b0
outpin4=bit7 'Set data to MSB
if Temp=8 then
high 5 'Clock idles high
pulsout 6,Pout_Start 'Pause 2ms by pulsing dummy pin (needs >2ms high stop clock pulse)
else
pulsout 5,Pout 'Clock high for 200us to latch data on pin1
pulsout 6,Pout 'Pause 200us by pulsing dummy pin (low clock)
endif
b0=b0*2 'Shift left
next Temp
Return
Interrupt:
if Status=1 then
if pin7=1 then
Dat=65527 'Pause SOMO-14D if it is playing
gosub Send_Data2
endif
Status=0 'Set status to pause
low 0 'Status indicator low (pause LED lit)
Pause 1000 'Pause to allow button release '
loop1:
if pin1=0 then loop1 'Wait for next button push
Dat=65527 'Resume SOMO-14D from pause state
gosub Send_Data2
Status=1 'Set status to run
high 0 'Status indicator high (run LED lit)
else
Status=1 'Set status to run
high 0 'Status indicator high (run LED lit)
endif
Pause 2000 'Pause to allow button release
setint %00000010,%00000010 'Reset interrupt
return