BASIC stamp manual v2.2

SERIN - BASIC Stamp Command Reference
Page 398 BASIC Stamp Syntax and Reference Manual 2.2 www.parallax.com
that use a 7-bit data mode do so in order to take advantage of the parity
feature. Parity can detect some communication errors, but to use it you
lose one data bit. This means that incoming data bytes transferred in 7E
(even-parity) mode can only represent values from 0 to 127, rather than
the 0 to 255 of 8N (no-parity) mode.
Usually a device requires only 1 stop bit per byte. Occasionally, however,
you may find a device that requires 2 or more stop bits. Since a stop bit is
really just a delay between transmitted bytes (leaving the line in a resting
state) the BASIC Stamp can receive transmissions with multiple stop bits
per byte without any trouble. In fact, sometimes it is desirable to have
multiple stop bits (see the “SERIN Troubleshooting” section, below, for
more information).
The example below will receive a single byte through I/O pin 1 at 2400
baud, 8N1, inverted:
SYMBOL serData = B2
SERIN 1, N2400, serData
--or--
serData VAR Byte
SERIN 1, 16780, [serData]
Here, SERIN will wait for and receive a single byte of data through pin 1
and store it in the variable serData. If the BASIC Stamp were connected to
a PC running a terminal program (set to the same baud rate) and the user
pressed the "A" key on the keyboard, after the SERIN command executed,
the variable serData would contain 65, the ASCII code for the letter "A"
(see the ASCII character chart in Appendix A).
What would happen if, using the example above, the user pressed the "1"
key? The result would be that serData would contain the value 49 (the
ASCII code for the character "1"). This is a critical point to remember:
every time you press a character on the keyboard, the computer receives
the ASCII value of that character. It is up to the receiving side (in serial
communication) to interpret the values as necessary. In this case, perhaps
we actually wanted serData to end up with the value 1, rather than the
ASCII code 49.
A SIMPLE FORM OF SERIN.
A
SIMPLE NUMERIC CONVERSION; ASCII
TEXT TO DECIMAL
.
Note: This is written with the BS2's
Baudmode value. Be sure to adjust the
value for your BASIC Stamp model.
All
2
1