Sie sind auf Seite 1von 4

Experiment #23b: Expanded Outputs

Experiment #23b:
Expanding Outputs
This experiment demonstrates further expansion of BASIC Stamp outputs by cascading two 75x595
shift registers.

(Schematic on the next page)

Behind The Scenes

The 75x595 has a Serial Output pin (9) that allows the cascading of multiple devices for more
outputs. In this configuration, the Clock and Latch pins are shared to keep all devices synchronized.

When cascading multiple shift registers, you must send the data for the device that is furthest down
the chain first. Subsequent SHIFTOUT sequences will "push" the data through each register until the
data is loaded into the correct device. Applying the latch pulse at that point causes the new data in
all shift registers to appear at the outputs.

The demo program illustrates this point by independently displaying a binary counter and a ping-
pong visual display using two 75x595 shift registers and eight LEDs for each. Note that the counter
display is controlled by the 75x595 that is furthest from the BASIC Stamp, so its data is shifted out
first.

StampWorks Manual Version 1.2 • Page 141


Experiment #23b: Expanded Outputs

Building The Circuit (Note that schematic is NOT chip-centric)

Page 142 • StampWorks Manual Version 1.2


Experiment #23b: Expanded Outputs

' ==============================================================================
'
' File...... Ex23b - 74HC595 x 2.BS2
' Purpose... Expanded outputs with 74HC595
' Author.... Parallax
' E-mail.... stamptech@parallaxinc.com
' Started...
' Updated... 01 MAY 2002
'
' {$STAMP BS2}
'
' ==============================================================================

' ------------------------------------------------------------------------------
' Program Description
' ------------------------------------------------------------------------------

' This program demostrates a simple method of turning three Stamp lines into
' 16 outputs with two 74HC595 shift registers. The data lines into the second
' 74HC595 is fed by the SQh output (pin 9) of the first. The clock and latch
' pins of the second 74HC595 are connected to the same pins on the first.

' ------------------------------------------------------------------------------
' I/O Definitions
' ------------------------------------------------------------------------------

DataOut CON 0 ' serial data out (74HC595.14)


Clock CON 1 ' shift clock (74HC595.11)
Latch CON 2 ' output latch (74HC595.12)

' ------------------------------------------------------------------------------
' Constants
' ------------------------------------------------------------------------------

DelayTime CON 100

' ------------------------------------------------------------------------------
' Variables
' ------------------------------------------------------------------------------

pattern VAR Byte ' output pattern


counter VAR Byte

StampWorks Manual Version 1.2 • Page 143


Experiment #23b: Expanded Outputs

' ------------------------------------------------------------------------------
' Initialization
' ------------------------------------------------------------------------------

Initialize:
LOW Latch ' make output and keep low
pattern = %00000001

' ------------------------------------------------------------------------------
' Program Code
' ------------------------------------------------------------------------------

Go_Forward:
counter = counter + 1 ' update counter
GOSUB Out_595
PAUSE DelayTime ' put pattern on 74x595
pattern = pattern << 1 ' shift pattern to the left
IF (pattern = %10000000) THEN Go_Reverse ' test for final position
GOTO Go_Forward ' continue in this direction

Go_Reverse:
counter = counter + 1
GOSUB Out_595
PAUSE DelayTime
pattern = pattern >> 1
IF (pattern = %00000001) THEN Go_Forward
GOTO Go_Reverse

' ------------------------------------------------------------------------------
' Subroutines
' ------------------------------------------------------------------------------

Out_595:
SHIFTOUT DataOut, Clock, MSBFirst, [counter] ' send counter to 2nd 74HC595
SHIFTOUT DataOut, Clock, MSBFirst, [pattern] ' send pattern to 1st 74HC595
PULSOUT Latch, 5 ' latch outputs
RETURN

Page 144 • StampWorks Manual Version 1.2

Das könnte Ihnen auch gefallen