Specifications
BASIC Stamp II
Parallax, Inc. • BASIC Stamp Programming Manual 1.8 • Page 305
2
Reverse
REVERSE
pin
Reverse the data direction of the specified pin.
•
Pin
is a variable/constant (0–15) that specifies the I/O pin to use.
This pin will be placed into the opposite of its current input/
output mode by inverting the corresponding bit of the DIRS
register.
Explanation
Reverse is convenient way to switch the I/O direction of a pin. If the
pin is an input and you Reverse it, it becomes an output; if it’s an out-
put, Reverse makes it an input.
Remember that “input” really has two meanings: (1) Setting a pin to
input makes it possible to check the state (1 or 0) of external circuitry
connected to that pin. The state is in the corresponding bit of the INS
register. (2) Setting a pin to input also disconnects the output driver
(corresponding bit of OUTS). The demo program below illustrates this
second fact with a two-tone LED blinker.
Demo Program
Connect the circuit of figure I-16 to pin 0 and run the program below.
The LED will alternate between two states, dim and bright. What’s
happening is that the Reverse instruction is toggling pin 0 between
input and output states. When pin 0 is an input, current flows through
R1, through the LED, through R2 to ground. Pin 0 is effectively discon-
nected and doesn’t play a part in the circuit. The total resistance en-
countered by current flowing through the LED is R1 + R2 = 440Ω. When
pin 0 is Reversed to output, current flows through R1, through the
LED, and into pin 0 to ground (because of the 0 written to OUT0). The
total resistance encountered by current flowing through the LED is R1,
220Ω. With only half the resistance, the LED glows brighter.
OUT0 = 0 ' Put a low in the pin 0 output driver.
again:
pause 200 ' Brief (1/5th second) pause.
REVERSE 0 ' Invert pin 0 I/O direction.
goto again ' Repeat forever.










