BASIC Stamp FAQ

STAMP FAQS PROGRAMMING INFORMATION
Last Revised On: 7/21/00 Page: 18
How do I input or output data in parallel on the I/O pins?
All BASIC Stamps have predefined variables that refer to the I/O pins. On the BASIC Stamp I, the PINS variable
refers to all eight I/O pins. Thus code such as:
SYMBOL Snapshot = B0
Snapshot = PINS
would copy the current state of all I/O pins (an 8-bit byte) into the variable Snapshot. Similarly:
DIRS = %11111111 ‘Set all eight pins as outputs
PINS = 150
would set the eight output pins to the binary form of 150, or %10010110.
On the BASIC Stamp II, IIe and IIsx, the PINS variable was replaced with the INS and OUTS variables. Both
INS and OUTS refer to all sixteen pins, while their derivatives, INL, INH, OUTL and OUTH refer to the low and
high bytes (groups of 8 pins). For example, the following code will input 8-bits in parallel from the lower 8 pins:
Snapshot VAR BYTE
Snapshot = INL
The following code will output 8-bits in parallel from the upper 8 pins:
DIRS = %1111111100000000 ‘Set upper 8 pins to outputs
OUTH = 255
Why do the BASIC Stamp’s output pins toggle briefly when I use the SLEEP, NAP or END
commands or allow my program to end naturally?
Inside the BASIC Stamp’s interpreter chip is a watchdog timer whose main purpose is to reset the interpreter chip
if, for some reason, it should stop functioning properly. The SLEEP and NAP commands also utilize the watchdog
timer to periodically (every 2.3 seconds to be exact) “wake-up” the BASIC Stamp from its low-power mode.
Upon reset, the I/O pins are set to inputs for approximately 18 mS before returning to their previous directions and
states. If you have an output pin set to a logical 1 state (+5V) and you use the SLEEP command, every 2.3
seconds during sleep mode that I/O pin will switch to an input for 18 mS causing a momentary signal loss. This
“power glitch” is easily viewable with an LED and a 470 ohm resister tied to an I/O pin and switched on just before
entering sleep mode. In many cases this problem can be remedied by tying a pull-up or pull-down resistor to the
I/O pin in question to provide a constant source of power should the I/O pin change directions. Allowing a
PBASIC program to end naturally, or using the END command, will exhibit the same “power glitch” behavior
because the interpreter chip enters a low-power state. The BASIC Stamp II, IIe and IIsx includes the STOP
command which acts just like END, except the output pins remain driven.