27220 Parallax Inc, 27220 Datasheet - Page 45

BOOK STAMPWORKS

27220

Manufacturer Part Number
27220
Description
BOOK STAMPWORKS
Manufacturer
Parallax Inc
Datasheet

Specifications of 27220

Accessory Type
Booklet
Product
Microcontroller Accessories
Lead Free Status / RoHS Status
Not applicable / Not applicable
For Use With/related Products
StampWorks
Lead Free Status / RoHS Status
Lead free / RoHS Compliant, Not applicable / Not applicable
Behind the Scenes
As explained in Experiment #1, the state of the BASIC Stamp output bits is stored in
a RAM register called OUTS.
corresponding to I/O pins P0 – P3. Since OUTA is part of the BASIC Stamp’s general
purpose (RAM) memory, values can be written to and read from it like any other
variable.
In this program we simply transfer (copy) the contents of 4-bit variable cntr to
OUTA (alias for the LEDs). Since P0 – P3 have been made outputs, this causes the
value of cntr to be displayed on the LEDs in binary format.
Challenge yourself: Modify the program to count backwards.
Q: Can we get the same results without using the cntr variable?
A: Yes – simply use
Write Code like a Pro
Since we’re dealing with multiple LEDs as a group and we cannot take advantage of
the PIN type declaration, we’re forced to use a standard variable (OUTA in this case)
to update the LEDs simultaneously. When possible, it’s best to group outputs to
match the natural boundaries of the BASIC Stamp I/O and memory structure. Our
programs will not always be as neat and tidy as this experiment, but when we do
indeed end up with groupings of four or eight pins, it’s best to use the BASIC
Stamp’s natural boundaries.
And note that while the LEDsDirs variable does not actually control the state of the
I/O pins, it does set pin directions and this is required for making these pins outputs
with a single line of code. For this reason, it is defined near the
the I/O definitions block. If we needed to make a design change that moved the
LEDs to OUTD, for example, the required changes would take place in the same area
of the program.
LEDs
LEDsDirs
LEDs
VAR
VAR
as the control variable for the FOR-NEXT loop.
The variable OUTA is the lower 4-bits of OUTS,
OUTD
DIRD
' LEDs on P12 – P15
' DIRS control for LEDs
LEDs
declaration in

Related parts for 27220