Shift, then latch
SER carries the bits, SRCLK moves them along, and RCLK decides the instant they become light. Three wires, and the third one is the one that stops the display flickering through eight wrong shapes on every update.
Two registers, not one
The chip on the board holds a byte twice over.
The first copy is the shift register: eight cells in a row, each handing its bit to the next one every time SRCLK goes high. Bits enter at one end on SER and walk along. After eight pulses the whole byte is in.
The second copy is the output register, and it is what the eight segment pins actually show. It does not change while the shift register is filling. It changes once, completely, when RCLK goes high.
Run it and watch which of the two rows moves:
Why the second register exists
Without it, every clock pulse would be visible on the pins. Sending a 3
after a 7 would put four or five wrong shapes on the glass on the way, and at
the rate a clock updates you would see it as a permanent flicker.
With it, the display goes from one digit straight to the next. Nothing in between is ever shown, because nothing in between ever reaches the pins.
In code that is three lines, and the order is not negotiable:
digitalWrite(PIN_RCLK, LOW); // hold the outputs still
shiftOut(PIN_SER, PIN_SRCLK, MSBFIRST, value); // eight bits, eight clocks
digitalWrite(PIN_RCLK, HIGH); // now show them, all at onceshiftOut is an Arduino function, not a feature of the chip. It wiggles the
data pin and the clock pin eight times and then returns. The latch is yours.
MSBFIRST decides which bit lands where
The third argument to shiftOut says which end of the byte goes down the wire
first. MSBFIRST sends bit 7 first, and because each pulse pushes everything
one place further along, the bit sent first ends up furthest from the input —
on the chip's last output.
So with MSBFIRST, bit 7 lands on the output the board labels H and bit 0
on the one labelled A. That is the mapping every segment table on the
internet assumes, and it is why one byte draws one
digit without any rearranging.
Send LSBFIRST by mistake and every byte arrives mirrored. Nothing is
damaged and nothing is miswired — you simply get a different, recognisable,
wrong shape, which is the easiest fault in this book to identify.
When it does not work
Every cell in the register hands its bit to the cell after it, and the first cell takes whatever is on SER at that moment. Eight pulses and the byte has walked all the way in. The bit you send first ends up furthest along, which is why MSBFIRST puts bit 7 on the last output.
After every byte you want to see. You can shift two bytes and latch once — that is exactly how two chained boards update together. What you must not do is latch in the middle of a byte, because then the outputs show half of the old value and half of the new one.
It does not. shiftOut only drives the data and clock pins; the latch is yours to pulse, which is why every example has digitalWrite on RCLK either side of the shiftOut call. Leave it out and the display never changes.
Yes — a 74HC595 is deliberately shaped like an SPI device, with SER as MOSI and SRCLK as the clock. SPI in hardware is far faster than shiftOut's software loop. For one digit updating a few times a second, shiftOut is simpler and nobody can tell the difference.
The fourteen pins, what each one does, and the two the chip has that the board does not bring out.
The driver board →Edit this page — content/books/seven-segment/shift-then-latch.mdx
Questions about this product
See what other owners have asked, and read their solutions.
24-Pack 0.56" 7-Segment LED with 74HC595 Driver
Loading discussions…
Discuss this article
Ask about this page. The answer stays here, on the page it belongs to, for whoever hits the same wall next.