BASIC stamp manual v2.2
5: BASIC Stamp Command Reference – SERIN
BASIC Stamp Syntax and Reference Manual 2.2 • www.parallax.com • Page 407
The unwanted x data is stored in yOffset then replaced by the desired y
data. This is a sneaky way to filter out a number of any size without using
an extra variable. With a little creativity, you can combine the InputData
modifiers to filter and extract almost any data.
Parity is a simple error-checking feature. When a serial sender is set for
even parity (the mode the BASIC Stamp supports) it counts the number of
1s in an outgoing byte and uses the parity bit to make that number even.
For instance, if it is sending the 7-bit value: %0011010, it sets the parity bit
to 1 in order to make an even number of 1s (four).
The receiver also counts the data bits to calculate what the parity bit
should be. If it matches the parity bit received, the serial receiver assumes
that the data was received correctly. Of course, this is not necessarily true,
since two incorrectly received bits could make parity seem correct when
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. Table 5.97 and Table 5.98 show appropriate
Baudmode settings for different BASIC Stamp models. 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
Main:
SERIN 1, 24660, Bad_Data, [serData]
DEBUG ? serData
STOP
Bad_Data:
DEBUG "Parity error."
STOP
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
USING PARITY AND HANDLING PARITY
ERRORS
.
All
2
All
2