
SHIFTOUT - BASIC Stamp Command Reference
Page 316
•
BASIC Stamp Programming Manual 2.0b
•
www.parallaxinc.com
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} 'STAMP directive (specifies a BS2)
DataP CON 0 ' Data pin to 74HC595.
Clock CON 1 ' Shift clock to 74HC595.
Latch CON 2 ' Moves data from register to output latch.
Counter VAR BYTE ' Counter for demo program.
' 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] ' Send the bits.
PULSOUT Latch,1 ' Transfer to outputs.
PAUSE 50 ' Wait briefly.
Counter = C 1 ' Increment counter.
GOTO Again ' Do it again.
2
e
2
sx
2
p
2
74HC595
To P0
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 P2
To P1
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.
Figure 5.40: SHIFTOUT Timing
Diagram. Refer to the SHIFTOUT
Quick Answers table for timing
information on t
h
, t
l
, t
a
and t
b
.
Summary of Contents for BASIC Stamp 2e
Page 1: ...BASIC Stamp Programming Manual Version 2 0c...
Page 34: ...Quick Start Guide Page 32 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Page 340: ...ASCII Chart Page 338 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Page 342: ...Reserved Words Page 340 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Page 346: ...Conversion Formatters Page 344 BASIC Stamp Programming Manual 2 0b www parallaxinc com...