Thursday, November 4, 2010

How to control 16 leds with only 3 I/O

The idea is quite simple: using a shift register to drive a led matrix using only few I/O of a microcontroller. Here I'll show you a my idea on how to drive 16 leds using only 3 I/Os with a Latched Shift Register 74HC595:

The microcotroller is connected to this circuit using the lines I've named as CLOCK, DATA and LATCH. 

The 74HC595 has a shift register and a latch. Incoming data are sent into shift register  using pin 14 (DS, serial data in) and pin 11 (SH_CP, Shift register clock). When we've  finished to sent serial data, we must  transfer data from shift register to the latch pulling high the pin 12 (ST_CP, Storage clock). If pin 13 (OE, output enable) is pulled down, the output pins (Q0-Q7) will reflect the latch status. Pin 10 is the Master Reset, pulling it down will cause the reset of the shift register. Pin 9 is serial data out and is used to drive more 74HC595.

We must feed data on DATA line using CLOCK and keeping LATCH down. When we have finished to send data, LATCH line must be pulled high and data are transferred from shift register to latch and value is displayed on leds.  We must pull LATCH down before start a new transfer but leds will remain in actual state. This is possible because pin 13 (OE = output enabled) is always low and then outputs are always enabled.

In order to display a value on 16 leds, data must be multiplexed. Entire first row will be lighted from serial value 0001 1111 : remember that high nibble drives the columns, low nibble drives the rowss. Entire second row will be lighted sending value  0010 1111 . Second led of third row (row=3 column=2) will be lighted sending value 0010 0010 and so on. Using a latched shift register will prevent the ghosting effect on leds.

Here there is an article in italian language I've written about using a shift register 74LS164 with a picmicro microcontroller. The informations and some code are about the same for 74HC595. The only two difference are:

- on 74HC595 data are sent from MSB to LSB, then the first bit you send on data line will be the bit n°8
- after you've send data, you must enable and then disable latch.

I have successfully tested this circuit. I've written a very long article on how to use this circuit witch a picmicro microcontroller. Article is in italian language, you can find it  clicking here

There are some examples here on how to use one or more 74HC595 with Arduino.


74HC595 datasheet