BASIC stamp manual v2.2

SEROUT – BASIC Stamp Command Reference
Page 420 BASIC Stamp Syntax and Reference Manual 2.2 www.parallax.com
Here, SEROUT will transmit a byte equal to 65 (the ASCII value of the
character "A") through pin 1. If the BASIC Stamp were connected to a PC
running a terminal program (set to the same baud rate) the character "A"
would appear on the screen (see the ASCII character chart in Appendix A).
What if you really wanted the value 65 to appear on the screen? If you
remember from the discussion in the SERIN command, "It is up to the
receiving side (in serial communication) to interpret the values…" In this
case, the PC is interpreting the byte-sized value to be the ASCII code for
the character "A". Unless you're also writing the software for the PC, you
can't change how the PC interprets the incoming serial data, so to solve
this problem, the data needs to be translated before it is sent.
The SEROUT command provides a formatter, called the decimal
formatter, which will translate the value 65 to two ASCII codes for the
characters "6" and "5" and then transmit them. Look at the following code:
SEROUT 1, N2400, (#65)
--or--
SEROUT 1, 16780, [DEC 65]
Notice the decimal formatter in the SEROUT command. It is the “#” (for
the BS1) or “DEC” (for all BS2 models) that appears just to the left of the
number 65. This tells SEROUT to convert the number into separate ASCII
characters which represent the value in decimal form. If the value 65 in the
code were changed to 123, the SEROUT command would send three bytes
(49, 50 and 51) corresponding to the characters "1", "2" and "3".
All BS2 models have many more conversion formatters available for the
SEROUT command. See the “Additional Conversion Formatters” section
below for more information.
The SEROUT command sends quoted text exactly as it appears in the
OutputData list:
SEROUT 1, N2400, ("Hello" CR)
SEROUT 1, N2400, ("Num = ", #100)
--or--
A
SIMPLE NUMERIC CONVERSION; DECIMAL
TO
ASCII NUMERIC TEXT.
This is written with the BS2's Baudmode
value. Be sure to adjust the value for
your BASIC Stamp model.
1
All
2
All
2
1