BASIC stamp manual v2.2
SHIFTOUT – BASIC Stamp Command Reference
Page 438 • BASIC Stamp Syntax and Reference Manual 2.2 • www.parallax.com
74HC595
To P 0
1
2
3
4
5
6
7
8
16
15
14
13
12
11
10
9
QB
QC
QD
QE
QF
QG
QH
GND
VCC
QA
DATA IN
OE
LATCH
CLK
RESET
SQH
Vss
LEDs
470 (all)
Ω
Vdd
Vdd
Vss
To P 2
To P 1
Figure 5.44: Circuit for Demo
Program SHIFTOUT.bs2.
Demo Program (SHIFTOUT.bs2)
' 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}
' {$PBASIC 2.5}
Dpin PIN 0 ' data pin to 74HC595
Clk PIN 1 ' shift clock to 74HC595
Latch PIN 2 ' latch 74HC595 outputs
counter VAR Byte
Setup:
LOW Latch ' initialize latch output
' 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
NOTE: This example program can be
used with all BS2 models by changing
the $STAMP directive accordingly.
All
2