Specifications
BASIC Stamp II
Parallax, Inc. • BASIC Stamp Programming Manual 1.8 • Page 311
2
The DEC modifier tells Serin to
convert decimal numeric text
into binary form and store the
result in serData. Receiving “123”
followed by a space or other non-
numeric text results in the value
123 being stored in serData. DEC
is one of a family of conversion
modifiers available with Serin;
see table I-4 for a list. All of the
conversion modifiers work simi-
larly: they receive bytes of data,
waiting for the first byte that falls
within the range of symbols they
accept (e.g., “0” or “1” for binary,
“0” to “9” for decimal, “0” to “9”
and “A” to “F” for hex, and “+”
or “-” for signed variations of any
type). Once they receive a nu-
meric symbol, they keep accept-
ing input until a non-numeric
symbol arrives or (in the case of
the fixed length modifiers) the
maximum specified number of
digits arrives.
While very effective at filtering
and converting input text, the modifiers aren’t completely foolproof.
For instance, in the example above, Serin would keep accepting text
until the first non-numeric text arrived—even if the resulting value
exceeded the size of the variable. After Serin, a byte variable would
contain the lowest 8 bits of the value entered; a word would contain
the lowest 16 bits. You can control this to some degree by using a modi-
fier that specifies the number of digits, such as DEC2, which would
accept values only in the range of 0 to 99.
Collecting Strings
Serin can grab sequences of incoming bytes and store them in array
variables using the STR modifier. See table I-5. Here is an example that
Calculating Baudmode
for BS2 Serin
Bits 0 through 12 of the baudmode are the bit period,
expressed in microseconds (µs). Serin’s actual bit period
is always 20µs longer than specified. Use the following
formula to calculate the baudmode bit period for a given
baud rate:
Step 1: Figure the Bit Period (bits 0—12)
(INT means ‘convert to integer;’ drop the numbers to the right of the decimal point.)
Bit 13 lets you select one of two combinations of data
bits and parity:
Step 2: Set Data Bits and Parity (bit 13)
1,000,000
baud rate
()
– 20INT
= 8 bits, no parity
= 7 bits, even parity
0
8192
Bit 14 tells Serin whether the data is inverted (as when it
comes directly from a standard COM port) or noninverted
(after passing through a line receiver):
Step 3: Select the Polarity of Serial Input (bit 14)
= noninverted
= inverted
Add your choice to the sum of steps 1 and 2. The result
is the correct serial baudmode for use by Serin.
0
16384
If you’re more comfortable thinking in terms of bits,
here’s a bit map of Serin’s baudmode:
FYI: Bit Map of Serin Baudmode
xP
d
BBBBBBBBBBBBB
1514131211109876543210
p
Bit period, 0 to 8191µs (+20µs)
Data bits, parity
(0 = 8 bits, no parity; 1 = 7 bits, even parity
Polarity (0 = noninverted; 1 = inverted)
Not used by Serin.
Serin through pin 16 (SIN) is always inverted, regardless of the
polarity setting. However, polarity will still affect fpin, if used.
Figure I-19
Step 1: Calculate the Bit Period (bits 0-12)










