SEROUT - BASIC Stamp Command Reference
Page 298
•
BASIC Stamp Programming Manual 2.0b
•
www.parallaxinc.com
SEROUT 1, N2400, ( 65 )
--or--
SEROUT 1, 16780, [ 65 ]
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 the
appendix).
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 the other BASIC Stamps) 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".
The BS2, BS2e, BS2sx and BS2p have many more conversion formatters
available for the SEROUT command. See the “Additional Conversion
Formatters” section below for more information.
A
SIMPLE NUMERIC CONVERSION
;
DECIMAL TO
ASCII
NUMERIC TEXT
.
1
1
2
e
2
sx
2
p
2
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.
This is written with the BS2's
BaudMode value. Be sure to adjust
the value for your BASIC Stamp.
2
e
2
sx
2
p
2
Summary of Contents for BASIC Stamp 2e
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...