#picaxe 28x1
setfreq m8
SYMBOL pin=b3
SYMBOL var=b4
SYMBOL temp=b5
SYMBOL temp2=b6
SYMBOL temp3=b7
'portc7 is used instead of out0 which is used for simplelan
LOW portc 7
''Works without disconnect
''but could give a little extra speed to disable ?
'disconnect
sertxd ("BOOT",cr,lf)
'Read from eeprom to simplelan
for temp=20 to 27
temp3 = temp + 60
read temp3,temp2
serout 0, t1200, ("!AT0W",temp,":",temp2, CR)
next
do
'handle all outputs
pin=0
var=20
gosub switchoutput
pin=1
var=21
gosub switchoutput
pin=2
var=22
gosub switchoutput
pin=3
var=23
gosub switchoutput
pin=4
var=24
gosub switchoutput
pin=5
var=25
gosub switchoutput
pin=6
var=26
gosub switchoutput
pin=7
var=27
gosub switchoutput
pause 500
'Save status every ~1min
b10 = b10 + 1
if b10 = 250 then
GOSUB saveeeprom
b10 = 0
endif
loop
switchoutput:
'Read 20(var pos) and 1 (pin number) from shared vars
SEROUT 0, t1200, ("!AT0R",#var)
SERIN [1000,timedout1],0, t1200, #b0
timedout1:
SEROUT 0, t1200, ("!AT0R",#var)
SERIN [1000,timedout2],0, t1200, #b1
timedout2:
SEROUT 0, t1200, ("!AT0R",#var)
SERIN [1000,timedout3],0, t1200, #b2
if b0 = b1 and b1 = b2 then
'sertxd ("Switching ",#pin," ",#var," to ",#b0,cr,lf)
if b0 = 0 then
if pin = 0 then
low portc 7
else
low pin
endif
endif
if b0 = 1 then
if pin = 0 then
high portc 7
else
high pin
endif
endif
if b0 = 2 then
if pin = 0 then
low portc 7
else
low pin
endif
pause 10000 '5sec at 8mhz
if pin = 0 then
high portc 7
else
high pin
endif
serout 0, t1200, ("!AT0W",#var,":","1", CR) 'Set status back to 1
endif
endif
timedout3:
RETURN
saveeeprom:
'Save to eeprom
for temp=20 to 27
temp3 = temp + 60
read temp3,temp2
SEROUT 0, t1200, ("!AT0R",#temp)
SERIN [1000,ttimedout1],0, t1200, #b0
ttimedout1:
SEROUT 0, t1200, ("!AT0R",#temp)
SERIN [1000,ttimedout2],0, t1200, #b1
ttimedout2:
SEROUT 0, t1200, ("!AT0R",#temp)
SERIN [1000,skipsave],0, t1200, #b2
if b0 = b1 and b1 = b2 then
if b0 = 2 then 'Dont save while cycling
goto skipsave
endif
if temp2 != b0 then
write temp3,b0
endif
endif
skipsave:
next
RETURN