BASIC Stamp Syntax and Reference Manual
Version 2.2
Warranty
Parallax Inc. warrants its products against defects in materials and workmanship for a period of 90 days from receipt of
product. If you discover a defect, Parallax Inc. will, at its option, repair or replace the merchandise, or refund the purchase
price. Before returning the product to Parallax, call for a Return Merchandise Authorization (RMA) number. Write the
RMA number on the outside of the box used to return the merchandise to Parallax. Please enclose the following along with
the returned merchandise: your name, telephone number, shipping address, and a description of the problem. Parallax will
return your product or its replacement using the same shipping method used to ship the product to Parallax.
14-Day Money-Back Guarantee
If, within 14 days of having received your product, you find that it does not suit your needs, you may return it for a full
refund. Parallax Inc. will refund the purchase price of the product, excluding shipping/handling costs. This guarantee is
void if the product has been altered or damaged. See the Warranty section above for instructions on returning a product to
Parallax.
Copyrights and Trademarks
This documentation is copyright 1994-2005 by Parallax Inc. By downloading or obtaining a printed copy of this
documentation or software you agree that it is to be used exclusively with Parallax products. Any other uses are not
permitted and may represent a violation of Parallax copyrights, legally punishable according to Federal copyright or
intellectual property laws. Any duplication of this documentation for commercial uses is expressly prohibited by Parallax
Inc. Duplication for educational use is permitted, subject to the following Conditions of Duplication: Parallax Inc. grants the
user a conditional right to download, duplicate, and distribute this text without Parallax’s permission. This right is based on
the following conditions: the text, or any portion thereof, may not be duplicated for commercial use; it may be duplicated
only for educational purposes when used solely in conjunction with Parallax products, and the user may recover from the
student only the cost of duplication.
This text is available in printed format from Parallax Inc. Because we print the text in volume, the consumer price is often
less than typical retail duplication charges.
BASIC Stamp, Stamps in Class, Board of Education, Boe-Bot, Todder, SumoBot, and SX-Key are registered trademarks of
Parallax, Inc. If you decide to use registered trademarks of Parallax Inc. on your web page or in printed material, you must
state that “(registered trademark) is a registered trademark of Parallax Inc.” upon the first appearance of the trademark
name in each printed document or web page. HomeWork Board, Parallax, and the Parallax logo are trademarks of Parallax
Inc. If you decide to use trademarks of Parallax Inc. on your web page or in printed material, you must state that
“(trademark) is a trademark of Parallax Inc.”, “upon the first appearance of the trademark name in each printed document
or web page. Other brand and product names are trademarks or registered trademarks of their respective holders.
ISBN #1-928982-32-8
Errata
While great effort is made to assure the accuracy of our texts, errors may still exist. If you find an error, please let us know
by sending an email to editor@parallax.com. We continually strive to improve all of our educational materials and
documentation, and frequently revise our texts. Occasionally, an errata sheet with a list of known errors and corrections for
a given text will be posted to our web site, www.parallax.com. Please check the individual product page’s free downloads
for an errata file.
Disclaimer of Liability
Parallax Inc. is not responsible for special, incidental, or consequential damages resulting from any breach of warranty, or
under any legal theory, including lost profits, downtime, goodwill, damage to or replacement of equipment or property, or
any costs of recovering, reprogramming, or reproducing any data stored in or used with Parallax products. Parallax Inc. is
also not responsible for any personal damage, including that to life and health, resulting from use of any of our products.
You take full responsibility for your BASIC Stamp application, no matter how life-threatening it may be.
Access Parallax via Internet
We maintain very a active web site for your convenience. These may be used to obtain software, communicate with
members of Parallax, and communicate with other customers. Access information is shown below:
Web:
General e-mail:
Tech. e-mail:
http://www.parallax.com
info@parallax.com
support@parallax.com
Internet BASIC Stamp Discussion List
We maintain active web-based discussion forums for people interested in Parallax products. These lists are accessible from
www.parallax.com via the Support
→
Discussion Forums menu. These are the forums that we operate from our web site:
•
•
•
•
•
•
•
BASIC Stamps – This list is widely utilized by engineers, hobbyists and students who share their BASIC
Stamp projects and ask questions.
®
Stamps in Class – Created for educators and students, subscribers discuss the use of the Stamps in
Class curriculum in their courses. The list provides an opportunity for both students and educators to
ask questions and get answers.
Parallax Educators –Exclusively for educators and those who contribute to the development of Stamps
in Class. Parallax created this group to obtain feedback on our curricula and to provide a forum for
educators to develop and obtain Teacher’s Guides.
Translators – The purpose of this list is to provide a conduit between Parallax and those who translate
our documentation to languages other than English. Parallax provides editable Word documents to our
translating partners and attempts to time the translations to coordinate with our publications.
Robotics – Designed exclusively for Parallax robots, this forum is intended to be an open dialogue for a
robotics enthusiasts. Topics include assembly, source code, expansion, and manual updates. The Boe-
Bot
®
, Toddler
®
, SumoBot
®
, HexCrawler and QuadCrawler robots are discussed here.
SX Microcontrollers and SX-Key – Discussion of programming the SX microcontroller with Parallax
®
rd
assembly language SX – Key tools and 3 party BASIC and C compilers.
Javelin Stamp – Discussion of application and design using the Javelin Stamp, a Parallax module that is
®
programmed using a subset of Sun Microsystems’ Java programming language.
Supported Hardware, Firmware and Software
This manual is valid with the following software and firmware versions:
BASIC Stamp Model
BASIC Stamp 1
BASIC Stamp 2
BASIC Stamp 2e
BASIC Stamp 2sx
BASIC Stamp 2p
BASIC Stamp 2pe
BASIC Stamp 2px
Firmware
1.4
1.0
1.1
1.1
1.4
1.1
1.0
Windows Interface
2.2
2.2
2.2
2.2
2.2
2.2
2.2
The information herein will usually apply to newer versions but may not apply to older versions. New software can be
obtained free on web site (www.parallax.com). If you have any questions about what you need to upgrade your product,
please contact Parallax.
Credits
Authorship and Editorial Review Team: Jeff Martin, Jon Williams, Ken Gracey, Aristides Alvarez, and Stephanie Lindsay;
Cover Art: Jen Jacobs; Technical Graphics, Rich Allred; with many thanks to everyone at Parallax Inc.
Contents
PREFACE ...................................................................... 5
INTRODUCTION TO THE BASIC STAMP ..................................... 7
BASIC S
TAMP
M
ODEL
C
OMPARISON
T
ABLE
.........................................................................8
BASIC S
TAMP
1 H
ARDWARE
.............................................................................................10
BASIC S
TAMP
2 H
ARDWARE
.............................................................................................13
BASIC S
TAMP
2
E
H
ARDWARE
...........................................................................................15
BASIC S
TAMP
2
SX
H
ARDWARE
.........................................................................................17
BASIC S
TAMP
2
P
H
ARDWARE
...........................................................................................19
BASIC S
TAMP
2
PE
H
ARDWARE
.........................................................................................21
BASIC S
TAMP
2
PX
H
ARDWARE
.........................................................................................23
G
UIDELINES AND
P
RECAUTIONS
.........................................................................................25
BASIC S
TAMP
P
ROGRAMMING
C
ONNECTIONS
....................................................................27
QUICK START GUIDE ....................................................... 29
USING THE BASIC STAMP EDITOR........................................ 35
T
HE
P
ROGRAMMING
E
NVIRONMENT
....................................................................................35
C
OMPILER
D
IRECTIVES
......................................................................................................43
S
PECIAL
F
UNCTIONS
.........................................................................................................46
S
ETTING
P
REFERENCES
....................................................................................................55
A
DVANCED
C
OMPILATION
T
ECHNIQUES
..............................................................................68
F
EATURES FOR
D
EVELOPERS
.............................................................................................75
BASIC STAMP ARCHITECTURE............................................ 81
RAM O
RGANIZATION
(BS1)...............................................................................................81
RAM O
RGANIZATION
(BS2, BS2
E
, BS2
SX
, BS2
P
, BS2
PE
) .................................................82
D
EFINING AND
U
SING
V
ARIABLES
.......................................................................................84
The Rules of Symbol Names ......................................................................................86
Defining Array Variables .............................................................................................87
Aliases and Variable Modifiers ...................................................................................89
C
ONSTANTS AND
C
OMPILE
-
TIME
E
XPRESSIONS
...................................................................94
N
UMBER
R
EPRESENTATIONS
..............................................................................................96
O
RDER OF
O
PERATIONS
..................................................................................................102
I
NTEGER
M
ATH
R
ULES
.....................................................................................................103
U
NARY
O
PERATORS
........................................................................................................105
Absolute Value (ABS) ...............................................................................................105
Cosine (COS) ...........................................................................................................106
Decoder (DCD) .........................................................................................................106
BASIC Stamp Syntax and Reference Manual 2.2
•
www.parallax.com
•
Page 1