Home / Learn Chip Programming / 7-Segment Displays and Multiplexing

7-Segment Displays and Multiplexing

Drive 4 digits with only 12 pins by multiplexing.

In shortDrive 4 digits with only 12 pins by multiplexing.

Theory in plain words

Multiplex loopTurn all digits offOutput segments for digit nEnable digit nwait 2 msnext digit
Multiplex loop

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

Display any numberTry it Yourself

The table SEG[] is exactly what you put in your C code. Bit 0 = segment a ... bit 6 = segment g, bit 7 = dot.

Multiplex refresh (call every 2 ms from a timer)
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;
}
Tip:Each segment needs its own resistor (220 to 470 ohm). In multiplexed mode, peak current can be higher but the average stays safe. Use transistors on the digit lines.

Quick quiz

1. Why multiplex?

2. Minimum refresh to avoid flicker?

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.