ASCII Seven-Segment Decoder: Mapping Characters to Display Segments
A seven-segment decoder converts characters (usually hexadecimal digits 0–F or ASCII characters) into the seven signals that drive a seven-segment display. This article explains how to map ASCII characters to seven-segment patterns, offers a reference mapping, and provides example code and usage notes for terminal and embedded contexts.
1. Seven-segment basics
A standard seven-segment display has segments labeled a–g plus an optional decimal point (dp). Each segment is either on (1) or off (0). A common binary representation packs segments into a single byte; a common bit order is:
- bit 0 = a
- bit 1 = b
- bit 2 = c
- bit 3 = d
- bit 4 = e
- bit 5 = f
- bit 6 = g
- bit 7 = dp (optional)
Using this ordering, the pattern for “0” (segments a,b,c,d,e,f on; g off) is 0b00111111 = 0x3F.
2. Which ASCII characters to support
Decide the character set your decoder needs. Common choices:
- Digits: ‘0’–’9’
- Hex letters: ‘A’–’F’ (or lowercase)
- Some alphabetic characters that map well: A, C, E, F, H, L, P, U, Y
- Basic punctuation: ‘-’ (dash), ‘’ (underscore), ‘ ’ (space), ‘.’ (decimal point handled separately) Unsupported or ambiguous characters can map to a blank, dash, or a question-mark-like pattern.
3. Reference mapping table (bit patterns)
Below is a compact reference mapping (bit pattern in binary and hex) using the bit order above; dp bit omitted (0).
- ‘0’ → 0b00111111 = 0x3F
- ‘1’ → 0b00000110 = 0x06
- ‘2’ → 0b01011011 = 0x5B
- ‘3’ → 0b01001111 = 0x4F
- ‘4’ → 0b01100110 = 0x66
- ‘5’ → 0b01101101 = 0x6D
- ‘6’ → 0b01111101 = 0x7D
- ‘7’ → 0b00000111 = 0x07
- ‘8’ → 0b01111111 = 0x7F
- ‘9’ → 0b01101111 = 0x6F
- ‘A’/‘a’ → 0b01110111 = 0x77
- ‘B’/‘b’ (display as lowercase b) → 0b01111100 = 0x7C
- ‘C’/‘c’ → 0b00111001 = 0x39
- ’D’/’d’ (display as lowercase d) → 0b01011110 = 0x5E
- ‘E’/‘e’ → 0b01111001 = 0x79
- ‘F’/‘f’ → 0b01110001 = 0x71
- ‘H’/‘h’ → 0b01110100 = 0x74
- ‘L’/‘l’ → 0b00111000 = 0x38
- ‘P’/‘p’ → 0b01110011 = 0x73
- ‘U’/‘u’ → 0b00111110 = 0x3E
- ‘Y’/‘y’ → 0b01101110 = 0x6E
- ’-’ → 0b01000000 = 0x40
- ‘’ → 0b00001000 = 0x08
- ’ ‘ (space) → 0b00000000 = 0x00
Use a fallback pattern (e.g., 0x40 for ‘-’) for unrecognized characters.
4. Handling the decimal point
Treat the decimal point as the high bit (bit 7). To display ‘3.’ set pattern = base_pattern | 0x80. When parsing input strings, detect ‘.’ characters and set the dp bit on the preceding character’s pattern (or on a dedicated dp position).
5. Implementation examples
C (lookup table):
#include
uint8_t seg_table[128]; // initialize all to
Leave a Reply