Home / Learn Chip Programming / Shift Registers and LFSR

Shift Registers and LFSR

A shift register moves bits one place per clock. It converts serial to parallel, expands pins and generates pseudo random numbers.

In shortA shift register moves bits one place per clock. It converts serial to parallel, expands pins and generates pseudo random numbers.

Theory in plain words

74HC595 timingPut bit on DATAPulse SHIFT clockRepeat 8 timesPulse LATCHOutputs update
74HC595 timing

What it is

A chain of flip-flops where each output feeds the next input. SIPO (serial in, parallel out) and PISO do conversion. An LFSR feeds back XORed taps to make pseudo-random sequences.

Why we use it

The 74HC595 adds 8 outputs with 3 pins. UART and SPI are shift registers in hardware. LFSRs are used for CRC, random numbers, test patterns and scrambling.

How it works

On each clock edge every bit moves one place and a new bit enters. After 8 clocks, 8 bits sit in the register. Pulse the latch pin to copy them to the outputs.

Where it is used

  • 74HC595 for LEDs and 7-segment displays
  • SPI and UART hardware
  • Pseudo-random generators and CRC engines

Shift register and LFSR

Shift register with LEDs, and a 4 bit LFSRTry it Yourself

Send 8 bits with DATA and clock to fill the register. The LFSR visits all 15 non-zero states before repeating, a cheap pseudo-random generator.

Bit-banging a 74HC595 from C
void shift_out(uint8_t value) {
    for (int i = 7; i >= 0; i--) {
        if (value & (1 << i)) DATA_HIGH(); else DATA_LOW();     // MSB first
        CLK_HIGH(); CLK_LOW();                                   // shift clock pulse
    }
    LATCH_HIGH(); LATCH_LOW();                                   // copy to outputs
}
TypeInputOutputExample
SIPOserialparallel74HC595 (add outputs)
PISOparallelserial74HC165 (add inputs)
SISOserialserialdelay line
Ring / Johnson counterfeedbackparallelLED chasers

Quick quiz

1. Which chip adds 8 outputs using 3 pins?

2. What can an LFSR generate?

Common questions

Which chip adds 8 outputs using 3 pins?

74HC595. It is a serial in, parallel out shift register.

What can an LFSR generate?

Pseudo-random sequences. XOR feedback creates a long repeating sequence.