
SERIN - BASIC Stamp Command Reference
Page 278
•
BASIC Stamp Programming Manual 2.0b
•
www.parallaxinc.com
If you’re communicating with existing software or hardware, its speed(s)
and mode(s) will determine your choice of baud rate and mode. In
general, 7-bit/even-parity (7E) mode is used for text, and 8-bit/no-parity
(8N) for byte-oriented data. Note: the most common mode is
8-bit/no-parity, even when the data transmitted is just text. Most devices
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 = B0
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 the appendix).
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
C
HOOSING THE PROPER BAUD MODE
.
A
SIMPLE FORM OF
SERIN.
A
SIMPLE NUMERIC CONVERSION
;
ASCII
TEXT TO DECIMAL
.
1
2
e
2
sx
2
p
2
This is written with the BS2's
BaudMode value. Be sure to adjust
the value for your BASIC Stamp.
Summary of Contents for BASIC Stamp 1
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...