Home / Learn Chip Programming / 7-Segment Displays and Multiplexing
7-Segment Displays and Multiplexing
Drive 4 digits with only 12 pins by multiplexing.
Theory in plain words
What it is
A 7-segment digit has 7 LEDs (a to g) plus a dot. Multiplexing lights one digit at a time very fast so the eye sees all digits lit.
Why we use it
Cheap, bright and readable: clocks, meters, counters. It teaches timing, lookup tables and current limiting.
How it works
Common cathode: segments high, digit low. Use a lookup table from digit to segment bits. Refresh each digit every 2 to 5 ms (>60 Hz overall).
Where it is used
- Digital clock project
- Voltmeters and counters
- TM1637 / MAX7219 driver chips
Segment decoder
The table SEG[] is exactly what you put in your C code. Bit 0 = segment a ... bit 6 = segment g, bit 7 = dot.
static const uint8_t SEG[10] = {0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F};
void display_refresh(void) {
static uint8_t d = 0;
DIGITS_OFF(); // avoid ghosting
SEGMENT_PORT = SEG[digit_value[d]];
DIGIT_ON(d);
d = (d + 1) & 3;
}Quick quiz
1. Why multiplex?
One set of segment lines is shared by all digits.
2. Minimum refresh to avoid flicker?
Faster than the eye can see.
Common questions
Why multiplex?
Fewer pins and less current. One set of segment lines is shared by all digits.
Minimum refresh to avoid flicker?
About 60 Hz for the whole display. Faster than the eye can see.