5: BASIC Stamp Command Reference – SERIN
BASIC Stamp Programming Manual 2.0c
•
www.parallaxinc.com
•
Page 287
the data was wrong, or the parity bit itself could be bad when the rest of
the data was OK.
Many systems that work exclusively with text use (or can be set for) 7-
bit/even-parity mode. Tables 5.73, 5.74 and 5.75 show appropriate
BaudMode settings for different BASIC Stamps. For example, with the BS2,
to receive one data byte through pin 1 at 9600 baud, 7E, inverted:
SerData VAR BYTE
SERIN 1, 24660, [SerData]
That instruction will work, but it doesn’t tell the BS2 what to do in the
event of a parity error. Here’s an improved version that uses the optional
Plabel argument:
SerData VAR BYTE
SERIN 1, 24660, BadData, [SerData]
DEBUG ? SerData
STOP
BadData:
DEBUG "parity error"
If the parity matches, the program continues at the DEBUG instruction
after SERIN. If the parity doesn’t match, the program goes to the label
BadData. Note that a parity error takes precedence over other InputData
specifications (as soon as an error is detected, SERIN aborts and goes to
the Plabel routine).
In all the examples above, the only way to end the SERIN instruction
(other than RESET or power-off) is to give SERIN the serial data it wants.
If no serial data arrives, the program is stuck. However, you can tell the
BASIC Stamp to abort SERIN if it doesn’t receive data within a specified
number of milliseconds. For instance, to receive a decimal number
through pin 1 at 9600 baud, 8N, inverted and abort SERIN after 2 seconds
(2000 ms) if no data arrives:
Result VAR BYTE
SERIN 1, 16468, 2000, NoData, [DEC Result]
Debug CLS, ? Result
STOP
NoData:
DEBUG CLS, "timed out"
U
SING THE SERIAL TIME
-
OUT
FEATURE
.
2
e
2
sx
2
p
2
2
e
2
sx
2
p
2
2
e
2
sx
2
p
2
Summary of Contents for BASIC Stamp 2e
Page 1: ...BASIC Stamp Programming Manual Version 2 0c...
Page 34: ...Quick Start Guide Page 32 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Page 340: ...ASCII Chart Page 338 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Page 342: ...Reserved Words Page 340 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Page 346: ...Conversion Formatters Page 344 BASIC Stamp Programming Manual 2 0b www parallaxinc com...