BASIC Stamp FAQ
STAMP FAQS PROGRAMMING INFORMATION
Last Revised On: 7/21/00 Page: 21
How can I define an alias to an I/O pin or another variable?
In the BASIC Stamp I you could specify the following:
SYMBOL Counter = B0
SYMBOL Index = B0
SYMBOL LED = PIN0
to designate the symbol Index as an alias to the Counter variable and the symbol LED as an alias to I/O pin 0.
Since Counter and Index use the same register, B0, anytime Counter is changed, Index will change in the same way.
The symbol LED will always contain either a 1 or a 0 depending on the logical state of I/O pin 0.
In the BASIC Stamp II, IIe or IIsx you could specify the following:
Counter VAR BYTE
Index VAR Counter
LED VAR IN0
to designate the symbol Index as an alias to the Counter variable and the symbol LED as an alias to I/O pin 0.
Since Index uses the same memory space as Counter, anytime Counter is changed, Index will change in the same
way. The symbol LED will always contain either a 1 or a 0 depending on the logical state of I/O pin 0.
How do I reference a specific bit within a byte or word variable?
On the BASIC Stamp I there is only one general purpose word register, W0, and two general purpose byte
registers, B0 and B1, which are bit addressable. The predefined symbols Bit0 through Bit15 refer to the
corresponding bits within W0 as well as B0 and B1 since those two byte variables correspond to the lower and
upper bytes of W0 respectively. Thus Bit0 is the lowest bit of both W0 and B0 while Bit8 is the lowest bit of B1
(and the 9th bit of W0).
On the BASIC Stamp II, IIe and IIsx all the variables are bit addressable, as well as nibble addressable. You can
reference a specific part of a variable by specifying the variable name followed by a dot ‘.’ and then the name of the
portion you’re interested in. For example, bit 2 of a word variable called Temp can be referenced with the notation:
Temp.BIT2. Additionally, the second nibble of Temp can be referenced with: Temp.NIB1. The valid modifiers
are: BIT0 through BIT15, LOWBIT, HIGHBIT, NIB0 through NIB3, LOWNIB, HIGHNIB, BYTE0 through
BYTE3, LOWBYTE and HIGHBYTE.
How do I define a string variable?
A string variable is simply an array of bytes. Only the BASIC Stamp II, IIe and IIsx allows the explicit definition of
arrays. If, for example, you want to define a string variable called Text to hold 6 characters, use the following code:
Text VAR BYTE(6)
The elements of an array can be accessed by specifying the array name followed by an open parenthesis, an index
value and a close parenthesis. The first element is always index 0. For example, the second element, or character
in this case, can be referenced with: Text(1) and the last element with: Text(5). Byte arrays are useful for receiving a
string of characters via the SERIN command using the STR modifier. The BASIC Stamp II, IIe and IIsx allows
you to define arrays of bits, nibbles and words as well.