BASIC stamp manual v2.2

5: BASIC Stamp Command Reference – SHIFTIN
BASIC Stamp Syntax and Reference Manual 2.2 www.parallax.com Page 433
Here is a simple example:
result VAR Byte
SHIFTIN 0, 1, MSBPRE, [result]
Here, the SHIFTIN command will read I/O pin 0 (Dpin) and will generate
a clock signal on I/O 1 (Cpin). The data that arrives on Dpin depends on
the device connected to it. Let's say, for example, that a shift register is
connected and has a value of $AF (10101111) waiting to be sent.
Additionally, let's assume that the shift register sends out the most
significant bit first, and the first bit is on Dpin before the first clock pulse
(MSBPRE). The SHIFTIN command above will generate eight clock pulses
and sample the data pin (Dpin) eight times. Afterward, the result variable
will contain the value $AF.
By default, SHIFTIN acquires eight bits, but you can set it to shift any
number of bits from 1 to 16 with the Bits argument. For example:
result VAR Byte
SHIFTIN 0, 1, MSBPRE, [result\4]
Will only input the first 4 bits. In the example discussed above, the result
variable will be left with %1010.
Some devices return more than 16 bits. For example, most 8-bit shift
registers can be daisy-chained together to form any multiple of 8 bits; 16,
24, 32, 40... To solve this, you can use a single SHIFTIN instruction with
multiple variables. Each variable can be assigned a particular number of
bits with the Bits argument. As in:
resultLo VAR Word
resultHi VAR Nib
SHIFTIN 0, 1, MSBPRE, [resultHi\4, resultLo\16]
The above code will first shift in four bits into resultHi and then 16 bits into
resultLo. The two variables together make up a 20 bit value.
A SIMPLE SHIFTIN EXAMPLE.
C
ONTROLLING THE NUMBER OF BITS
RECEIVED
.