BASIC stamp manual v2.2

5: BASIC Stamp Command Reference – SHIFTOUT
BASIC Stamp Syntax and Reference Manual 2.2 www.parallax.com Page 437
Here is a simple example:
SHIFTOUT 0, 1, MSBFIRST, [250]
Here, the SHIFTOUT command will write to I/O pin 0 (Dpin) and will
generate a clock signal on I/O pin 1 (Cpin). The SHIFTOUT command will
generate eight clock pulses while writing each bit (of the 8-bit value 250)
onto the data pin (Dpin). In this case, it will start with the most significant
bit first as indicated by the Mode value of MSBFIRST.
By default, SHIFTOUT transmits eight bits, but you can set it to shift any
number of bits from 1 to 16 with the Bits argument. For example:
SHIFTOUT 0, 1, MSBFIRST, [250\4]
Will output only the lowest (rightmost) four bits (%1010 in this case). But
what if you want to output the leftmost bits of a given value? By adding
the right-shift operator (>>) to the code you can adjust the output as
required:
SHIFTOUT 0, 1, MSBFIRST, [(250 >> 2)\6]
will output the upper six bits (%111110 in this case).
Some devices require more than 16 bits. To solve this, you can use a single
SHIFTOUT command with multiple values. Each value can be assigned a
particular number of bits with the Bits argument. As in:
SHIFTOUT 0, 1, MSBFIRST, [250\4, 1045\16]
The above code will first shift out four bits of the number 250 (%1010) and
then 16 bits of the number 1045 (%0000010000010101). The two values
together make up a 20 bit value.
In the examples above, specific numbers were entered as the data to
transmit, but, of course, the SHIFTOUT command will accept variables
and expressions for the OutputData and even for the Bits argument.
A SIMPLE SHIFTOUT EXAMPLE.
C
ONTROLLING THE NUMBER OF BITS
TRANSMITTED
.
SHIFTOUT
ACCEPTS VARIABLES AND
EXPRESSIONS FOR
OUTPUTDATA AND
BITS ARGUMENTS.