read output
Archiver
Posts: 46,084
Hi all,
Thanks to the suggestions I have received previuosly about reading
output status. I have tried to implement them one at a time, however
I can not seem to read the staus of an output. I don't understand.
Can anyone tell me why the following code does not work.
I can read the keys, toggle the corresponding outputs, I just can not
read/dispaly its status.
I have tried outs.lowbit, outs.bit0 - no go!
'{$STAMP BS2p}
'{$PORT COM1}
dirs=%1111111111111111 '0=input >> 1=output
bps con 240 '9600 Baudrate
dly con 20 'Global pause delay..
key var byte 'key input varible
result var byte 'decoded key
status var outs.lowbit
auxio 'use aux i/o
Rx con 13 'Serin (receive) pin 13
pause 500
HIGH 11 'Set the pin high (Power LED on).
goto reset 'reset lcd
loop:
auxio
serin Rx,bps,[noparse][[/noparse]key]
if key=13 then tgl 'if key 13 is pressed then toggle
output
if key=8 then reset
key=key-48
if key<=10 then keyscan
key = key-7
Keyscan:
LOOKUP key, [noparse][[/noparse]48,55,56,57,52,53,54,49,50,51,65,66,67,68],result
mainio
output(result)
RR: 'Read Relay
if status(result)= 1 then displayc
goto displayo
tgl: 'Toggle output
mainio
toggle(result)
goto rr
displayc: 'display relay closed
serout 0,bps,[noparse][[/noparse]254,192]
pause dly
serout 0,bps,[noparse][[/noparse]"RLY ", (result), " CLOSED"] 'display status of
selected relay
pause 100
goto loop
displayo:
serout 0,bps,[noparse][[/noparse]254,192]
pause dly
serout 0,bps,[noparse][[/noparse]"RLY ", (result), " OPEN "]
pause 100
goto loop
reset:
debug "reset",cr
mainio
serout 0,bps,[noparse][[/noparse]1]
pause dly
serout 0,bps,[noparse][[/noparse]12]
pause dly
serout 0,bps, [noparse][[/noparse]"READY"]
goto loop
Thanks to the suggestions I have received previuosly about reading
output status. I have tried to implement them one at a time, however
I can not seem to read the staus of an output. I don't understand.
Can anyone tell me why the following code does not work.
I can read the keys, toggle the corresponding outputs, I just can not
read/dispaly its status.
I have tried outs.lowbit, outs.bit0 - no go!
'{$STAMP BS2p}
'{$PORT COM1}
dirs=%1111111111111111 '0=input >> 1=output
bps con 240 '9600 Baudrate
dly con 20 'Global pause delay..
key var byte 'key input varible
result var byte 'decoded key
status var outs.lowbit
auxio 'use aux i/o
Rx con 13 'Serin (receive) pin 13
pause 500
HIGH 11 'Set the pin high (Power LED on).
goto reset 'reset lcd
loop:
auxio
serin Rx,bps,[noparse][[/noparse]key]
if key=13 then tgl 'if key 13 is pressed then toggle
output
if key=8 then reset
key=key-48
if key<=10 then keyscan
key = key-7
Keyscan:
LOOKUP key, [noparse][[/noparse]48,55,56,57,52,53,54,49,50,51,65,66,67,68],result
mainio
output(result)
RR: 'Read Relay
if status(result)= 1 then displayc
goto displayo
tgl: 'Toggle output
mainio
toggle(result)
goto rr
displayc: 'display relay closed
serout 0,bps,[noparse][[/noparse]254,192]
pause dly
serout 0,bps,[noparse][[/noparse]"RLY ", (result), " CLOSED"] 'display status of
selected relay
pause 100
goto loop
displayo:
serout 0,bps,[noparse][[/noparse]254,192]
pause dly
serout 0,bps,[noparse][[/noparse]"RLY ", (result), " OPEN "]
pause 100
goto loop
reset:
debug "reset",cr
mainio
serout 0,bps,[noparse][[/noparse]1]
pause dly
serout 0,bps,[noparse][[/noparse]12]
pause dly
serout 0,bps, [noparse][[/noparse]"READY"]
goto loop
Comments
ascii characters and actual numerical values. You must have a firm
grasp on the difference and pay greater attention to when each
should be used if you intend to use your Stamp effectively. I've
added some reverse engineered pseudocode/comments and some suggested
DEBUG statements.
Your Stamp will most often tell you why things aren't working as you
expected if you just ask via a DEBUG statement.
Regards,
Steve
> Can anyone tell me why the following code does not work.
>
> I can read the keys, toggle the corresponding outputs, I just can
> not read/dispaly its status.
>
> I have tried outs.lowbit, outs.bit0 - no go!
>
> '{$STAMP BS2p}
> '{$PORT COM1}
>
> dirs=%1111111111111111 '0=input >> 1=output
> bps con 240 '9600 Baudrate
> dly con 20 'Global pause delay..
> key var byte 'key input varible
> result var byte 'decoded key
> status var outs.lowbit
> auxio 'use aux i/o
> Rx con 13 'Serin (receive) pin 13
>
> pause 500
> HIGH 11 'Set the pin high (Power LED on).
> goto reset 'reset lcd
>
> loop:
' use auxio
> auxio
' get single, serial byte
> serin Rx,bps,[noparse][[/noparse]key]
' if 13 ($0D, carriage return) goto toggle logic
> if key=13 then tgl 'if key 13 is pressed then toggle
> output
' if 08 ($08, backspace) goto reset logic
> if key=8 then reset
' convert ascii character in variable key to value 0-15
'*********************************
DEBUG CR, "raw key from keyboard: ", HEX2 key, " ", key
'*********************************
> key=key-48
> if key<=10 then keyscan
> key = key-7
>
'*********************************
DEBUG CR, "converted key value: ", DEC key
'*********************************
' select ascii character for result based on value in key
' 0, 7, 8, 9, 4, 5, 6, 1, 2, 3, A, B, C, D
> Keyscan:
> LOOKUP key, [noparse][[/noparse]48,55,56,57,52,53,54,49,50,51,65,66,67,68],result
'*********************************
DEBUG CR, "converted result: ", DEC result
'*********************************
' set pin # result to output
' (note above sets result to a character, not a value)
> mainio
> output(result)
>
' if outs.bit0( result ) = 1 goto display closed logic
' note again that if result is not a value from 0-15, this
' won't work as you expect
> RR: 'Read Relay
> if status(result)= 1 then displayc
> goto displayo
>
> tgl: 'Toggle output
> mainio
' toggle pin # result of mainio
' note again that if result is not a value from 0-15, this
' won't work as you expect
> toggle(result)
> goto rr
>
> displayc: 'display relay closed
> serout 0,bps,[noparse][[/noparse]254,192]
> pause dly
' display status msg, assumes result contains ascii numeric
> serout 0,bps,[noparse][[/noparse]"RLY ", (result), " CLOSED"] 'display status of
> selected relay
> pause 100
> goto loop
>
> displayo:
> serout 0,bps,[noparse][[/noparse]254,192]
> pause dly
' display status msg, assumes result contains ascii numeric
> serout 0,bps,[noparse][[/noparse]"RLY ", (result), " OPEN "]
> pause 100
> goto loop
>
> reset:
> debug "reset",cr
> mainio
> serout 0,bps,[noparse][[/noparse]1]
> pause dly
> serout 0,bps,[noparse][[/noparse]12]
> pause dly
> serout 0,bps, [noparse][[/noparse]"READY"]
> goto loop