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.
Theory in plain words
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
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.
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
}| Type | Input | Output | Example |
|---|---|---|---|
| SIPO | serial | parallel | 74HC595 (add outputs) |
| PISO | parallel | serial | 74HC165 (add inputs) |
| SISO | serial | serial | delay line |
| Ring / Johnson counter | feedback | parallel | LED chasers |
Quick quiz
1. Which chip adds 8 outputs using 3 pins?
It is a serial in, parallel out shift register.
2. What can an LFSR generate?
XOR feedback creates a long repeating sequence.
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.