Hi All
Working on the following code for a remote sensor unit link up to confirm 1 if the data between the two units is being sent correctly and 2 the sensors on the remote are working correctly.
I have as the following code will show used a number selection to inact the sub routines in the remote unit and a macro to determine action.
My concern is will I evently get a stack problem with the macro directing the responce to either obtain or option.
If so would it then be better to use GOTO rather than GOSUB
regards john
Working on the following code for a remote sensor unit link up to confirm 1 if the data between the two units is being sent correctly and 2 the sensors on the remote are working correctly.
I have as the following code will show used a number selection to inact the sub routines in the remote unit and a macro to determine action.
My concern is will I evently get a stack problem with the macro directing the responce to either obtain or option.
If so would it then be better to use GOTO rather than GOSUB
Code:
#picaxe 28x2
#no_data
#no_table
Symbol Qualifier= 254
symbol fail=b25
symbol want=b26
symbol lamp=w7
symbol dry=w8
symbol rh=w9
'#rem
'***************Remote unit routine****************
#MACRO Talk_Talk
if w5=w6 then:fail=0:serout B.0,T9600,("Y"):goto obtain:endif
if w5<>w6:then:if fail<2 then:goto option:else:serout B.0,T9600,("N"):fail=0:goto obtain:endif:endif
#endm
hintsetup %00000100
pause 1000
main:
enablebod 'low power
sleep 0 'woken up via pin B.2 attached to AUX on DRF sets hint and hint2 flags
disablebod 'power up
Serin B.1, T9600,(Qualifier,"Hello") 'call from master DRF unit
if hint2flag=1 then
high B.7
pause 50
serout B.0,T9600,(Qualifier,"ACK")
gosub obtain
endif
goto main
end
obtain:
serin B.1,T9600,want 'b5 from master
if want=$FF then 'end data request from master
goto main
endif
option:
select case want
case 1 gosub light
case 2 gosub temp
case 3 gosub rhhum
end select
light:
w5=123
serout B.0,T9600,(w5)
pause 20
serin B.1,T9600,w6
if w5<>w6 then
fail=fail+1
endif
Talk_Talk 'macro
return
temp:
w5=25
serout B.0,T9600,(w5)
pause 20
serin B.1,T9600,w6
if w5<>w6 then
fail=fail+1
endif
Talk_Talk 'macro
return
rhhum:
w5=75
serout B.0,T9600,(w5)
pause 20
serin B.1,T9600,w6
if w5<>w6 then
fail=fail+1
endif
Talk_Talk 'macro
return
'#endrem
'*******************Master call to remote routine**********************
#rem
pause 1000
MAIN:
low B.7
sertxd("b5 ",#b5,cr,lf)
recall:
serout A.1,T9600,(85,85,85,85,Qualifier,"Hello")
pause 20
serin[3000,recall], A.2,T9600,(Qualifier,"ACK")
high B.7
'call to measure light levels
b5=1
serout A.1,T9600,(b5)'tell remote unit which reading to undertake
serin A.2,T9600,lamp 'result from remote unit
pause 50
serout A.1,T9600,(lamp) 'bounce result back to check for errors
pause 50
serin A.2,T9600,b0 'conformation or error
if b0="N" then
sertxd("light sensor error",cr,lf)
endif
sertxd("lamp ",#lamp," b0 ",#b0," b5 ",#b5,cr,lf)
'call to measure tempreture
b5=2
serout A.1,T9600,(b5)'tell remote which reading to undertake
serin A.2,T9600,dry
pause 10
serout A.1,T9600,(dry)
pause 10
serin A.2,T9600,b0
if b0="N" then
serout B.1,N9600,("tempreture sensor error")
endif
sertxd("dry ",#dry," b0 ",#b0," b5 ",#b5,cr,lf)
'call to measure humidity
b5=3
serout A.1,T9600,(b5)'tell remote which reading to undertake
serin A.2,T9600,rh
pause 10
serout A.1,T9600,(rh)
pause 10
serin A.2,T9600,b0
if b0="N" then
serout B.1,N9600,("humidity sensor error")
endif
pause 100
sertxd("rh ",#rh," b0 ",#b0," b5 ",#b5,cr,lf)
pause 100
serout A.1,T9600,($FF)
for b10= 1 to 30
pause 1000
next b10
goto main
none:
serout B.1,N9600,("sensor unit failed to read")
goto main
#endrem