Specifications

BASIC Stamp II
Page 328 • BASIC Stamp Programming Manual 1.8 • Parallax, Inc.
Shiftin
SHIFTIN
dpin,cpin,mode,[result{\bits}{,result{\bits}...}]
Shift data in from a synchronous-serial device.
Dpin
is a variable/constant (0–15) that specifies the I/O pin that
will be connected to the synchronous-serial device’s data output.
This pin’s I/O direction will be changed to input and will remain
in that state after the instruction is completed.
Cpin
is a variable/constant (0–15) that specifies the I/O pin that
will be connected to the synchronous-serial device’s clock input.
This pin’s I/O direction will be changed to output.
Mode
is a value (0—3) or 2 predefined symbol that tells Shiftin the
order in which data bits are to be arranged and the relationship
of clock pulses to valid data. Here are the symbols, values, and
their meanings:
Symbol Value Meaning
MSBPRE 0 Data msb-first; sample bits before clock pulse
LSBPRE 1 Data lsb-first; sample bits before clock pulse
MSBPOST 2 Data msb-first; sample bits after clock pulse
LSBPOST 3 Data lsb-first; sample bits after clock pulse
(Msb is most-significant bit; the highest or leftmost bit of a nibble,
byte, or word. Lsb is the least-significant bit; the lowest or
rightmost bit of a nibble, byte, or word.)
Result
is a bit, nibble, byte, or word variable in which incoming
data bits will be stored.
Bits
is an optional entry specifying how many bits (1—16) are to
be input by Shiftin. If no bits entry is given, Shiftin defaults to 8
bits.
Explanation
Shiftin provides an easy method of acquiring data from synchronous-
serial devices. Synchronous serial differs from asynchronous serial (like
Serin and Serout) in that the timing of data bits is specified in relation-
ship to pulses on a clock line. Data bits may be valid after the rising or
falling edge of the clock line. This kind of serial protocol is commonly