One byte, one digit
Each of the 595's eight outputs drives one segment, so a digit is one byte: bit 0 is segment a, bit 6 is g, and bit 7 is the dot. The digit is common cathode, so a 1 lights its segment. 2 is 0x5B.
Eight outputs, eight segments
The net list gives the map, and it is the tidy one: each output to the segment of the same position.
| Bit | 595 output | Resistor | Digit leg | Segment |
|---|---|---|---|---|
| 0 | Q0 (QA), pin 15 | R2 | 7 | a, top |
| 1 | Q1 (QB), pin 1 | R1 | 6 | b, top right |
| 2 | Q2 (QC), pin 2 | R6 | 4 | c, bottom right |
| 3 | Q3 (QD), pin 3 | R7 | 2 | d, bottom |
| 4 | Q4 (QE), pin 4 | R8 | 1 | e, bottom left |
| 5 | Q5 (QF), pin 5 | R3 | 9 | f, top left |
| 6 | Q6 (QG), pin 6 | R4 | 10 | g, middle |
| 7 | Q7 (QH), pin 7 | R5 | 5 | the dot |
Nexperia calls the outputs Q0 to Q7; TI and most tutorials call them QA to QH. They are the same pins.
Why a 1 lights
The digit is common cathode: the eight LEDs share their negative end, and that end is on GND. An output that goes HIGH pushes current through its resistor and its segment to GND, and the segment lights. An output that is LOW leaves both ends of the LED at 0 V, and nothing flows.
So a byte is a picture of the digit. 2 needs a, b, g, e and d: bits 0, 1,
6, 4 and 3, which is 0b01011011, or 0x5B. The dot is bit 7 on its own:
0x80, added to any digit with | 0x80.
The table
const byte DIGITS[10] = {
0x3F, 0x06, 0x5B, 0x4F, 0x66, // 0 1 2 3 4
0x6D, 0x7D, 0x07, 0x7F, 0x6F, // 5 6 7 8 9
};These are the same ten bytes as the 0.56-inch digit's common-cathode table, because that board's outputs reach the segments in the same order. A table from a common-anode tutorial has every bit flipped: 2 is 0xA4 there, and on this board 0xA4 lights everything but the 2.
When it does not work
The table was written for a common-anode digit, where a 0 lights. This digit is common cathode and wants the opposite. Use the table in the book's sketch, or put a ~ in front of each byte.
Set bit 7: OR the digit's byte with 0x80. 5 is 0x6D and 5 with its dot is 0xED. The dot is its own LED on its own output, Q7, and costs one more segment's current.
Some. A, b, C, d, E and F make hexadecimal, and H, L, P and U are easy. A seven-segment B looks like an 8 and a D like a 0, which is why b and d are lower case. M, W, K and X do not work.
MSBFIRST or LSBFIRST, and the one-word mistake that mirrors every digit.
Which bit goes first →Edit this page — content/books/hc595-segment-led/one-byte-one-digit.mdx
Questions about this product
See what other owners have asked, and read their solutions.
74HC595 Segment LED
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.