Download The Electronisc Projects

Monday, October 17, 2011

Shift Register 74HC595 Tutorials

I am here providing a simple and very good tutorials for Shift register 74HC595


Basically a shift register will, in the end, let you expand on the digital outputs you have on your mictrocontroller. Each one of these 74HC595s can act like 8 more digital outputs, and you can daisy chain them. So you could hook 8 of them up next to each other and have control of 64 outputs.
But the way it works is a little confusing to think of at first, and these are helpful enough that it is really worth understanding what the heck is going on under the hood.
You can imagine a shift register as a row of chairs. In this particular case, with the 74HC595, we have a row of 8 chairs. Each chair is either empty (0), or someone is sitting it (1).
Now, every 10 seconds or so, someone rings a bell, and everyone has to get up and move one chair to the right. If there was someone in that rightmost chair, well they just go away. In that leftmost chair, you can either tell someone to sit in it, or just leave it empty.
Now bringing this idea back to the 74HC595: This shift register consists of 8 output pins, which are either high (1) or low (0). When you pull the SRCLK (Serial Clock) pin high (analogy to ringing the bell), every pin moves one to the right. The Last pin drops out, and the new pin’s state is defined by the SER (Serial) pin, and you can set that to either 1 (HIGH) or 0 (LOW).
How does this let me control LEDs again? Well, say you have 8 LEDs hooked up to the shift registers outputs, and we want to turn on the 1st, 3rd and the 8th LED. So… what we can do is clear out the register so all LEDs are off. Then we put in one high, move it right 4 spots, add one high, move it over 1, then add another high. See the image on the right, it will make more sense.
The great thing is that the shift register has this pin called RCLK or register clock. You can hold this pin LOW while you get everything setup and nothing on the display pins will change. Then when you are done, and everything is how you want, you pull the RCLK HIGH and the 74HC595 will display the new settings. So even though we are changing values in the register in 8 steps, it looks like it was just one step.

operation of 74HC595

Set MR=1
Set OE=0
Set STCP=0
Set SHCP=0

Give to DS the value of D7
toggle SHCP (to 1 and back to 0)
Give to DS the value of D6
toggle SHCP (to 1 and back to 0)
....
Give to DS the value of D0
toggle SHCP (to 1 and back to 0)
toggle STCP (to 1 and back to 0) to see the data in the output

SHCP shifts the data without changing the output state, when you are done shifting you toggle STCP to output the result




2.2. How to drive it

The circuit description covers use of the 74HC595. Use of the 74HC4094 (which may be cheaper and easier to find) is covered later in this document. First the strobe line is dipped low and back high again. This latches all the inputs into the 74HC165 input shift registers. Then the clocking begins. With each clock pulse, the data line is set to an output, and the appropriate data bit is presented on the line to be clocked into the output shift register. On the same clock pulse, the input shift register presents its next data bit to the microcontroller data pin. The data pin is set to an input, and this data bit read.
The number of clock pulses required is the larger of the number of inputs and the number of outputs. After this number of clock pulses, all the required output states have been shifted into position in the 74HC597 output shift registers, and another dipping of the "strobe" line is performed to set these states on the shift register output pins.
A timing diagram for this operation is shown below:
The points in this diagram are:
  • A: STROBE is pulsed low to latch inputs.
  • B: DATA line is set to an output, and appropriate data placed on it. CLOCK is pulsed high to shift this data bit into the chain, and get next bit from the chain.
  • C: DATA line is set to an input, and the data bit is read from the chain.
  • D: In this example there are more outputs than inputs, so from this point, the rest of the outputs are clocked out.
  • E: This is the rest of the outputs being clocked out.
  • F: Finally, the STROBE line is pulsed again to latch the outputs onto the output shift register output pins.
You can make the chain any length you want, with as many output stages or input stages as required. It may be all input stages, or it may be all output stages too. There are constants in the code where the dimensions of the shift register are defined, and they control how the software drives it.

No comments:

Post a Comment