There are possibilities in embedded design where you do not have enough I/O pins available in your microcontroller. That can be due to any reason, may be your application needs multiple LEDs or you want to use multiple 7-segment displays, but you don’t have required I/O pins in your microcontroller. Here comes a perfect component, shift register. Shift register accepts serial data and give parallel output. It’s requires only 3 pins to connect with your microcontroller and you will get more than 8 Output pins from it. One of the popular shift register is 74HC595. It has 8 bit storage register and 8 bit shift register. Learn more about shift registers here.

You will provide serial data to the shift register and it will be latched on the storage register and then the storage register will control the 8 outputs. If you want more output just add another shift register. By cascading two shift registers, you will get additional 8 outputs, total 16bit output.

Shift Register 74HC595:

Here is the pin out diagram of the 74HC595 as per the datasheet-

HC595 has 16pins; if we see the datasheet we will understand the pin functions-

The QA to QH, from pin numbers 1 to 7 and 15 used as 8 bit output from the shift register, where as the pin 14 is used for receiving the serial data. There is also truth table about how to use other pins and avail other functions of the shift register.

When we write the code for interfacing the 74HC595, we will apply this truth table for getting the desired outputs.

Now, we will interface 74HC595 with PIC16F877A and control 8 LEDs. We have interfaced 74HC595 shift register with other microcontrollers:

Circuit Diagram:

In circuit diagram, we have connected the serial data pin; clock and strobe (latch) pin on microcontroller’s RB0, RB1 and RB2 pin respectively. Here we have used one resistor for 8 LEDs. As per the truth table, we enabled output by connecting the pin 13 of 74HC595 to ground. The QH pin is left open as we will not cascade another 74HC595 with it. We disabled the clear input flag by connecting pin 10 of the shift register with VCC.

The Crystal oscillator is connected on the OSC pins of the microcontroller. PIC16F877A do not have any internal oscillator. In this project we will light up the led one by one from Q0 to Q7 using shift regitster.

In this function we accept 8bit data and send each bit using two bitwise operators left shift and AND operator. We first shift the data one by one and find out the exact bit whether it is 0 or 1 using AND operator with 0x01. Each data is stored by the clock pulse and final data output done using the latch or strobe pulse. In this process the data output will be MSB (Most Significant Bit) first.

In the main function we submitted the binary and made the output pins high one by one.

Comments

Hi!
I made almost the same today but with CD4094 and a little bit different parsing. I have to use MSB first method to display ok.
You first shift left with 0 so the first 'anding' and sending is the LSB. Maybe I didn't get it right. Can you explain it?