SHIFTOUT - BASIC Stamp Command Reference
LEDs
Vss
Demo Program (SHIFTOUT.bs2)
' This program uses the SHIFTOUT command to interface to the 74HC595 shift register as an
' 8-bit output port. The '595 requires a minimum of three inputs: data, clock, and latch. See
' the figure in the SHIFTOUT command description in the manual for wiring information.
' SHIFTOUT automatically handles the data and clock, pulsing the clock to shift data bits into
' the '595. An extra step (pulsing the latch input) is required to move the shifted bits in parallel
' onto the '595's output pins. Note: this code does not control the output-enable or reset lines
' of the '595. This means that before the BASIC Stamp first sends, the '595's output latches
' are turned on and may contain random data. In critical applications, you should hold
' output-enable high (disabled) until the BASIC Stamp can take control.
'{$STAMP BS2}
DataP
CON
Clock
CON
Latch
CON
Counter
VAR
BYTE
' This loop moves the 8-bit value 'counter' onto the output lines of the '595, pauses, then
' increments counter and repeats. The data is shifted msb first so that the msb appears on
' pin QH and the lsb on QA. Changing 'msbfirst' to 'lsbfirst' causes the data to
' appear backwards on the outputs.
Again:
SHIFTOUT DataP,Clock,MSBFIRST,[Counter]
PULSOUT Latch,1
PAUSE 50
Counter = Counter + 1
GOTO Again
Page 316 • BASIC Stamp Programming Manual 2.0b • www.parallaxinc.com
Ω
470
(all)
1
QB
VCC
2
QC
QA
3
QD
DATA IN
4
QE
OE
74HC595
5
QF
LATCH
6
QG
CLK
7
QH
RESET
8
GND
SQH
'STAMP directive (specifies a BS2)
0
' Data pin to 74HC595.
1
' Shift clock to 74HC595.
2
' Moves data from register to output latch.
' Counter for demo program.
' Send the bits.
' Transfer to outputs.
' Wait briefly.
' Increment counter.
' Do it again.
Vdd
16
15
14
To P0
13
Vss
12
To P2
11
To P1
Vdd
10
9
Figure 5.40: SHIFTOUT Timing
Diagram. Refer to the SHIFTOUT
Quick Answers table for timing
information on t
, t
, t
and t
h
l
a
2
2
2
2
e
p
sx
NOTE: This is written for the BS2
but can be used for the BS2e,
BS2sx and BS2p also. Locate the
proper source code file or modify
the STAMP directive before
downloading to the BS2e, BS2sx or
BS2p.
.
b
Need help?
Do you have a question about the BASIC Stamp 2e and is the answer not in the manual?