EN

Shift registers

Serial to parallel, parallel to serial and rotation, with the 74HC595 and the 74HC165

1. Simulator

8-bit register

2. 74HC595 chain

Outputs
MHz
/s

What a shift register is

A shift register is a row of D flip-flops in which the output of each goes to the input of the next. On each clock edge all the bits move one position: the one entering at one end pushes the others and the one at the other end leaves. This converts data from serial to parallel and from parallel to serial, delays signals by an exact number of cycles or builds ring and Johnson counters.

TypeInOutUse
SISOSerialSerialDelay line
SIPOSerialParallelMore outputs: LEDs, relays, displays
PISOParallelSerialMore inputs: push buttons, DIP switches
PIPOParallelParallelStorage register
UniversalBothBothShift left or right, like the 74HC194

74HC595: more outputs from three pins

The 74HC595 receives data on the SER pin, which shifts on each edge of SRCLK (shift clock). It also has a separate output register: the bits do not appear on outputs Q0–Q7 until an edge arrives on RCLK (latch). That way the outputs do not flicker while new data is loaded. The Q7' pin outputs the bit that falls off the end and connects to the SER of the next chip: with three microcontroller pins (data, clock and latch) you control 8, 16, 24 or more outputs. OE low enables the outputs, and PWM on OE dims all the LEDs at once.

digitalWrite(LATCH, LOW);
shiftOut(DATA, CLOCK, MSBFIRST, value);   // one byte per 74HC595
digitalWrite(LATCH, HIGH);                // the outputs change here

Each 74HC595 output comfortably gives about 6 mA and the whole chip should not exceed about 70 mA. For relays or larger loads, add a ULN2803 after it or use the TPIC6B595, which has power outputs.

74HC165: more inputs

The 74HC165 does the opposite: a low pulse on SH/LD copies all eight inputs into the register at once, and then each clock edge shifts one bit out on Q7. Several are chained by connecting the Q7 of one to the serial input SER of the previous one. It is used to read many push buttons or switches with three or four pins.

Shifting is multiplying and dividing

In a binary number, shifting all bits one position towards the most significant bit multiplies by 2, and towards the least significant bit divides by 2. That is why processors have shift instructions (in C, x << 1 and x >> 1) and use them to multiply and divide quickly by powers of 2. In rotation, the bit that leaves comes back in at the other end and nothing is lost.

Related: latches and flip-flops, counters, ULN2803 for relays and loads and multiplexers.