Have you ever wished
you had a few more output ports on your microcontroller? Have you
ever wanted to control 20 or 30 LED's? Well there is an easy way.
By using a 74HC595 8 bit shift register you can do it. The 595 will
give you an additional 8 output ports. Each pin on the 74HC595 can
handle 35ma. This make it excellent for driving small relays and
Large LED's. Oh, I forgot to mention. You can cascade
multiple 595's together to create more output pins.
The operation of the
595 is very simple. You shift in each bit MS bit first. This
is done by setting the Serial in pin high or low then taking the clock pin
from a low to a high state. Once 8 bits are shifted you latch the
data to the output lines by taking the latch pin from low to high.
If a pins was already high or low and its new state is the same.
There will be not change presented to that pin.
I don't want to dwell
to much on how the 74HC595 works because I have created a library called
595.lib. All you have to do is make a couple of library calls and
its like having extra output lines. I have even added a function
that lets you send multiple values to cascaded 595's.
Hookup
This first schematic
is for a single 595 connected to pins 0-2 on the Smart Module. You
can use any three pins just remember to change the init595 command to
reflect the change.

Schematic 1
The LED's shown are
the type with internal resistors. You can use normal one just make
sure use a 390ohm resistor.

A simple picture
showing a single 595 in action.
The next schematic
shows you how to cascade multiple 595's.

Schematic 2
You can keep cascading
multiple 595's just connect the QH pin on the previous 595 to the serin of
the next and tie all clk and Latch pins together.

Two 595's cascaded
The Library
Just place the library
into your lib directory of the Smart Module Editor.
Library description
download it here
init595(serin,clk,latch)
This function must be
called before any of the others.
serin is the serial
input pin to the 595.
clk is the clock pin on
the 595.
latch is the latch pin
on the 595.
set595(value)
This is the work horse
of the library. The value represents the 8 output pins on the 595.
So a value of 255 will set all the pins to high and value of 0 will set them
all low.
set595m(num,value1,.....)
If you cascade more than
1 595 you can use this command to access them.
num is used to tell the
function how many 595's are connected.
You then provide a value
for each 595.
high595(port)
This command sets an
individual port on the 595 to high. Ports are numbered from 0 to 7.
low595(port)
This command sets an
individual port on the 595 to low. Ports are numbered from 0 to 7.
Test Programs
Single 595
download it here
MOD A
func main()
dim x
init595(0,1,2)
again:
for x = 0 to 255
set595(x)
pause 10
next
goto again
endfunc
include lib\595.lib
This program counts from
0 - 255 and displays the output on the 8 LED's in binary.
Cascaded 595
download it here
MOD A
func main()
dim x
dim z
init595(0,1,2)
z=0
again:
for x = 0 to 255
set595m(2,x,z)
pause 10
next
z = z +1
goto again
endfunc
include lib\595.lib
This program counts from
0 - 65536 and displays the output on 16 LED's in binary.
Note: You must have the
595.lib file downloaded and located in the /lib directory of your Smart
Module Editor.
If you have any
questions or comments please contact me as msimpson@kronosrobotics.com