Seven Segment Display

If your embedded system only needs to display numbers, you can consider using a seven-segment display. The seven-segment display is a simple device composed of 8 LEDs (the decimal point being the 8th). These LEDs can be lit in different combinations to represent Arabic numerals and some English characters.

7 segment 128 states
Figure 1: The 128 States of a Seven-Segment Display

The segments of a seven-segment display are referred to by the letters A to G, with an optional decimal point (DP) for the display of non-integer numbers.

7SegDisplay 01 s7SegDisplay 02 s

Types of Seven-Segment Displays

There are two main types of seven-segment displays available. In a simple LED package, as shown in the figure above, typically all of the cathodes (negative terminals) or all of the anodes (positive terminals) of the segment LEDs are connected and brought out to a common pin; this is referred to as a "common cathode" or a "common anode" device. Hence, a 7-segment plus decimal point package will only require nine pins, though commercial products typically contain more pins and/or places where pins would go to match standard IC sockets.

Generally, common anode displays are more popular than common cathode displays since logic circuits can sink more current than they can source.

Displaying Numbers on a Seven-Segment Display

To display a number, you need to forward-bias the specific set of LEDs corresponding to the desired character.

Display a "0"
Common Cathode 0

To display the numerical digit "0," you must light up the LED segments corresponding to a, b, c, d, e, and f.
  • Common Cathode: Connect these pins to power.
  • Common Anode: Connect these pins to ground.
Display a "1"
Common Cathode 1

To display the numerical digit "1," you must light up the LED segments corresponding to b and c.
  • Common Cathode: Connect these pins to power.
  • Common Anode: Connect these pins to ground.

Displaying Letters and Hexadecimal Digits

Hexadecimal digits can also be displayed on a seven-segment display. A combination of uppercase and lowercase letters is used for letters 'A' to 'F' to ensure unique shapes for each hexadecimal digit. For example, a capital 'D' would look identical to a '0', and a capital 'B' would look identical to an '8' if not for this distinction. Additionally, the digit '6' must be displayed with the top bar lit to avoid ambiguity with the lowercase letter 'b'.

Encoding Methods for Seven-Segment Displays

A single byte can encode the full state of a seven-segment display. The most popular bit encodings is dpgfedcba and dpabcdefg, where each letter represents a particular segment in the display.

  • 'dp.g.f.e.d.c.b.a' encoding: Encode segments a to g to bit 0 to bit 6, with the decimal point (dp) on bit 7.
  • 'dp.a.b.c.d.e.f.g' encoding: Encode segments a to g to bit 6 to bit 7, with the decimal point (dp) on bit 7.

For example, in the dp.g.f.e.d.c.b.a encoding, a byte value of 0x06 would light up segments 'c' and 'b', displaying the number '1'.

Creating a Lookup Table for Hexadecimal Digits

A seven-segment display comprises 8 segments; we will label them a, b, c, d, e, f,  g, and dp. This is the standard way to label each segment LED. Now, we need to make a lookup table to encode hexadecimal digits.

Here, we consider the decimal point (dp) pins are not used, so the dp values are always set to 0. We only consider segments a to f. Now we have to decide for every hex number (0 to F) and figure out what segments must be lit.

Example:

  • Display '0':
    • We want a, b, c, d, e, f on and g off.
    • In the table, put '1' on segments a, b, c, d, e, f, and '0' on segment g.
    • So, the output for the "dp.g.f.e.d.c.b.a" encoding is 0, 0, 1, 1, 1, 1, 1, 1. The binary value is 0b0011 1111 (or hex value 0x3F).
  • Display '1':
    • We want b and c on, and the rest of the segments are off.
    • In the table, put '1' on segments b and c, and '0' on the rest of the segments.
    • So, the output for the "dp.g.f.e.d.c.b.a" encoding is 0, 0, 0, 0, 0, 1, 1, 0. The binary value is 0b0000 0110 (or hex value 0x06)

Below is a lookup table for hexadecimal encoding using a common cathode seven-segment display. If using a common anode display, the values must be inverted. (Hover over each character with your mouse to see which segments need to be illuminated to display it.)

Table 1: Seven-Segment Display Lookup Table for Hexadecimal Encodings

Digit Display Individual Segments Illuminated
Port [7:0] Port [7:0]
dp g f e d c b a dp.g.f.e.d.c.b.a dp.a.b.c.d.e.f.g
0 SevenSegment 064 s 0 0 1 1 1 1 1 1 0x3F 0x7E
1 SevenSegment 007 s 0 0 0 0 0 1 1 0 0x06 0x30
2 SevenSegment 092 s
3 SevenSegment 080 s
4 SevenSegment 103 s
5 SevenSegment 110 s
6 SevenSegment 126 s
7 SevenSegment 008 s
8 SevenSegment 128 s
9 SevenSegment 112 s
A SevenSegment 120 s
B SevenSegment 125 s
C SevenSegment 058 s
D SevenSegment 095 s
E SevenSegment 122 s
F SevenSegment 114 s

Using Current Limiting Resistors

When connecting seven-segment displays in a circuit, a current limiting resistor must be wired in series with each display segment. Any resistor value between 100Ω and 1KΩ will work for the LED resistor. A lower resistance will result in a brighter segment. It is best to use resistors of the same value so all the segments light up evenly.

© 2024 Air Supply Information Center (Air Supply BBS)