74HC595 digit/From a byte to a digit/04. One byte, one digit
From a byte to a digit · 04 of 9

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.

Bit595 outputResistorDigit legSegment
0Q0 (QA), pin 15R27a, top
1Q1 (QB), pin 1R16b, top right
2Q2 (QC), pin 2R64c, bottom right
3Q3 (QD), pin 3R72d, bottom
4Q4 (QE), pin 4R81e, bottom left
5Q5 (QF), pin 5R39f, top left
6Q6 (QG), pin 6R410g, middle
7Q7 (QH), pin 7R55the dot

Nexperia calls the outputs Q0 to Q7; TI and most tutorials call them QA to QH. They are the same pins.

One byte, one digit
Show
Decimal point
Binary
0b01011011
Segments lit
5 of 8
0x5B lights a, b, d, e, g. Each 1 puts its output HIGH, and current runs through that segment's resistor and LED to GND. A 0 leaves both ends of the LED at 0 V, and it stays dark.

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

Every segment lights except the ones I wanted.

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.

How do I light the decimal point?

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.

Can it show letters?

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.

Where this goes next

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

Community

Questions about this product

See what other owners have asked, and read their solutions.

Ask a question ↗

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.

Browse Modules and blocks on the forum →