It all depends on the context. It depends on what else the Stamp is doing and how it "hears from the computer" now. If the Stamp is just listening for something from the computer via a serial port, you can use the SERIN timeout feature (read the Manual chapter on the SERIN statement). If there's something else going on, you'll have to give details.
I have this program running, but I want it to set x to 0 when there is no input through the Debug Terminal. I have it hooked up to the computer continuously via USB.
[noparse][[/noparse]quote]
' {$STAMP BS2}
' {$PBASIC 2.5}
x VAR Byte
y VAR Byte
z VAR Byte
DO
SEROUT 0, 84, [noparse][[/noparse]z, x]
DEBUGIN y
IF (y=97) THEN
z=$C6
x=127
ELSEIF (y=115) THEN
z=$C5
x=127
ENDIF
LOOP
Rather than DEBUGIN, use the SERIN statement with a I/O pin # of 16. This is the same as the programming port.
Use the timeout feature as described in the Manual chapter on the SERIN statement. If the timeout occurs, set x to 0.
This has some limitations. In particular, if the Debug Terminal sends a character while the Stamp program is doing
something else (than the DEBUGIN or SERIN), the Stamp will miss the character.
Notice in the paragraph near the bottom of page 171 (DEBUGIN) that this is a special case of SERIN with inverted mode, 9600 Baud, 8 bits, 1 stop bit, and no parity. There are tables of Baud constants on page 397 of the Manual. 8 bit, no parity, inverted, 9600 Baud on a BS2 uses 16468 as the Baud constant.
As far as I know, the Stamp Editor just detects incoming characters and that causes the debug terminal to start.
Ok, so now I have this program, and it isn't doing anything. I think there must be an error with my SERIN command, but I don't know what it is.
' {$STAMP BS2}
' {$PBASIC 2.5}
x VAR Byte
y VAR Byte
z VAR Byte
DO
DEBUG CR
SEROUT 0, 84, [noparse][[/noparse]z, x]
SERIN 16, 84, Continue, 2000, Time_Out, [noparse][[/noparse]y]
Continue:
IF (y=97) THEN
z=$C6
x=127
ELSEIF (y=115) THEN
z=$C5
x=127
ENDIF
Time_Out:
x=0
LOOP
Thanks
Post Edited (CorbettROV) : 10/30/2008 10:08:20 PM GMT
Unfortuntely, the change in baud did not make it work. Nothing happens except an LED blinks on the BASIC Stamp and on the TReX Jr, so I know it's receiving something, it's just not working. Here is my code, does anyone see anything wrong?:
' {$STAMP BS2}
' {$PBASIC 2.5}
x VAR Byte
y VAR Byte
z VAR Byte
DO
DEBUG CR
SEROUT 0, 84, [noparse][[/noparse]z, x]
SERIN 16, 16468, Continue, 2000, Time_Out, [noparse][[/noparse]y]
Continue:
IF (y=97) THEN
z=$C6
x=127
ELSEIF (y=115) THEN
z=$C5
x=127
ENDIF
Time_Out:
x=0
LOOP
The last thing done in the loop is to set x to zero. It's always done.
Why do you have a parity error label when you've specified no parity? Read the SERIN description again.
At a minimum, you need to put a GOTO after the ENDIF that goes to just before the LOOP
' {$STAMP BS2}
' {$PBASIC 2.5}
x VAR Byte
y VAR Byte
z VAR Byte
DO
DEBUG CR
SEROUT 0, 84, [noparse][[/noparse]z, x]
SERIN 16, 16468, 2000, Time_Out, [noparse][[/noparse]y]
IF (y=97) THEN
z=$C6
x=127
ELSEIF (y=115) THEN
z=$C5
x=127
ENDIF
GOTO Continue
Time_Out:
x=0
Continue:
LOOP
' {$STAMP BS2}
' {$PBASIC 2.5}
x VAR Byte
y VAR Byte
z VAR Byte
DO
DEBUG CR
SEROUT 0, 84, [noparse][[/noparse]z, x]
SERIN 16, 16468, Continue, 10000, Time_Out, [noparse][[/noparse]y]
LOOP
Continue:
IF (y=97) THEN
z=$C6
x=127
ELSEIF (y=115) THEN
z=$C5
x=127
ENDIF
Time_Out:
z=$C4
x=0
I want it to go to "Continue" if it gets a y value and if it times out, i\I want it to go to "Time_Out". It's not working though.
Comments
[noparse][[/noparse]quote]
' {$STAMP BS2}
' {$PBASIC 2.5}
x VAR Byte
y VAR Byte
z VAR Byte
DO
SEROUT 0, 84, [noparse][[/noparse]z, x]
DEBUGIN y
IF (y=97) THEN
z=$C6
x=127
ELSEIF (y=115) THEN
z=$C5
x=127
ENDIF
LOOP
Use the timeout feature as described in the Manual chapter on the SERIN statement. If the timeout occurs, set x to 0.
This has some limitations. In particular, if the Debug Terminal sends a character while the Stamp program is doing
something else (than the DEBUGIN or SERIN), the Stamp will miss the character.
What would I set as the baud rate?
And if I use SERIN instead of DEBUGIN, would the debug terminal come up?
As far as I know, the Stamp Editor just detects incoming characters and that causes the debug terminal to start.
Don't forget the timeout time and label.
··· DEBUG CR
in your Stamp program, and Debug will start in the PC.· Then you can type stuff in.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
· -- Carl, nn5i
Thanks
Post Edited (CorbettROV) : 10/30/2008 10:08:20 PM GMT
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
There are 10 types of people that understand binary, those who do, and those who don't.
Thanks, I'll test this out Monday.
The last thing done in the loop is to set x to zero. It's always done.
Why do you have a parity error label when you've specified no parity? Read the SERIN description again.
At a minimum, you need to put a GOTO after the ENDIF that goes to just before the LOOP
I want it to go to "Continue" if it gets a y value and if it times out, i\I want it to go to "Time_Out". It's not working though.
Thanks