Specifications
BASIC Stamp II
Page 330 • BASIC Stamp Programming Manual 1.8 • Parallax, Inc.
data this will give us; each bit will be the inverse of the previous one. If
the first bit is 1, the sequence will be 10101010101... Connect the flip-
flop as shown in figure I-25b and run the following program:
setup:
if IN0 = 1 then continue ' Force FF to start
pulsout 1,10 ' sequence with data=1.
continue:
SHIFTIN 0,1,msbpre,[b1] ' Shiftin msb-first, pre-clock.
debug "Pre-clock: ",bin8 b1,cr ' Show the result in binary.
SHIFTIN 0,1,msbpost,[b1] ' Shiftin msb-first, post-clock.
debug "Post-clock: ",bin8 b1,cr ' Show the result in binary.
You can probably predict what this demonstration will show. Both
Shiftin instructions are set up for msb-first operation, so the first bit
they acquire ends up in the msb (leftmost bit) of the variable. Look at
figure I-25a; the first data bit acquired in the pre-clock case is 1, so the
pre-clock Shiftin returns %10101010. The data line is left with a 1 on it
because of the final clock pulse.
The post-clock Shiftin acquires its bits after each clock pulse. The ini-
tial pulse changes the data line from 1 to 0, so the post-clock Shiftin
returns %01010101.
By default, Shiftin acquires eight bits, but you can set it to shift any
number of bits from 1 to 16 with an optional entry following the vari-
able name. In the example above, substitute this for the first Shiftin
instruction:
SHIFTIN 0,1,msbpre,[b1\4] ' Shiftin 4 bits.
The debug window will display %00001010.
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... You can use a single Shiftin instruction with multiple
variables. Each variable can be assigned a particular number of bits
with the backslash (\) option. Modify the previous example:
SHIFTIN 0,1,msbpre,[b1\5,b2] ' 5 bits into b1; 8 bits into b2.
debug "1st variable: ",bin8 b1,cr
debug "2nd variable: ",bin8 b2,cr










