Skip to content
Tutorials Center
My learning

Topics

Lesson 50 of 57 ยท Projects

Project: Seven-Segment Display Decoder

Design a BCD to seven-segment decoder from scratch. Build the truth table, simplify each segment with K-maps and don't-cares, then test it in Python with ASCII art.

Calculators, microwave ovens, clocks and elevator panels all show digits with the same trick: seven small light-emitting bars arranged in a figure 8. A circuit called a seven-segment decoder takes a binary number and decides which bars to switch on. It is a classic first project because it uses almost everything from the Boolean-algebra part of this course: a truth table, seven output functions, Karnaugh maps and don't-care conditions.

In this project you will go from a drawing of ten digits to simplified logic equations, then test them in Python and render the digits as ASCII art. At the end you will compare your design against the table to prove it correct.

The specification

The display has seven segments, named a to g clockwise from the top, with g in the middle:

TEXT
 aaa
f   b
f   b
 ggg
e   c
e   c
 ddd

The decoder has four inputs A B C D (with A the most significant bit) carrying a decimal digit in BCD, the binary-coded decimal form from BCD, Gray Code and ASCII. It has seven outputs a to g, one per segment. We assume a common-cathode display where 1 means "light this segment".

The design flow

Specify Decide which segments each digit lights.
Truth table Seven outputs for each of 16 inputs.
K-maps Simplify every segment with don't-cares.
Verify Test all ten digits automatically.

The same flow works for any combinational circuit.

1 / 2

The digits are conventional, with one choice to make: how to draw 6, 7 and 9. We light the top bar for 6 and the bottom bar for 9, and leave 7 with only the top and right bars (abc). The segments for each digit are:

Digit Segments on
0 a b c d e f
1 b c
2 a b d e g
3 a b c d g
4 b c f g
5 a c d f g
6 a c d e f g
7 a b c
8 a b c d e f g
9 a b c d f g

Step 1: the truth table

Four inputs give 16 rows, but BCD only uses the values 0 to 9. The codes 10 to 15 never occur, so we do not care what the decoder shows for them. Those rows are don't-cares, written X. Don't-cares are the secret to a smaller circuit: a K-map group may treat an X as a 1 whenever that makes the group bigger.

The program turns the table above into the truth table.

Python The truth table with don't-care rows

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Read down a column to see one segment's function. Segment a, for example, is on for 0, 2, 3, 5, 6, 7, 8 and 9, and off for 1 and 4. Each of the seven columns is a separate Boolean function of A B C D, and each gets its own K-map.

Step 2: K-maps

A K-map lays out a four-variable truth table as a 4ร—4 grid whose rows and columns follow Gray code (00, 01, 11, 10), so neighbouring cells differ in one variable. The program draws the map of any segment straight from the table. Here are segments e and c.

Python Drawing K-maps from the table

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Segment e

The map for e has four 1s: digits 0, 2, 6 and 8. The whole row AB = 11 and two cells of the row AB = 10 are don't-cares we may use.

  • The cells with B = 0 and D = 0 are 0, 2 and 8 (plus the X cell 10): that is the term B'D'.
  • The cells with C = 1, D = 0 cover 2 and 6 (plus the X cells 10 and 14): that is the term CD'.

So e = B'D' + CD'. Two small AND terms and one OR: this segment is on only for digits whose last bit is 0 and which are not 4.

Segment c

Segment c is on for every digit except 2. The only 0 in the whole map is at ABCD = 0010. With the X cells at 1010 acting as a 1, that 0 can be isolated with a single group of two cells covering B=0, C=1, D=0. The function is the complement of that product, which De Morgan turns into a sum:

c = B + C' + D

Once you spot that a function is "almost always 1", it is easier to simplify the single 0 and invert.

The remaining segments

Working the other five maps the same way, with the don't-cares, gives this set (the prime on a letter means NOT, + means OR, and juxtaposition means AND):

TEXT
a = A + C + BD + B'D'
b = B' + C'D' + CD
c = B + C' + D
d = A + B'D' + B'C + CD' + BC'D
e = B'D' + CD'
f = A + C'D' + BC' + BD'
g = A + BC' + B'C + CD'

Your result may look slightly different if you choose other groups, because there can be more than one minimal cover. What matters is that each expression agrees with the truth table on rows 0 to 9. The values for rows 10 to 15 are whatever your groups happen to produce, and that is fine.

The A term appears in four of the seven equations (a, d, f and g). That is the don't-care trick at work: rows 8 and 9 have A = 1, and the X rows 10 to 15 also have A = 1, so A alone can cover them.

Step 3: verify with code

Never trust hand-simplified logic. A four-input function has only 16 rows, so you can test it exhaustively. The program below turns the equations into a decoder, checks it against the table for every digit, and then draws digits as ASCII art using the segment values.

Python Decoder, check and ASCII display

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The checker reports no mismatches, and the ASCII digits are readable. Look at what the same equations print for the unused codes 10 to 15: the output is some pattern, and nobody cares, because BCD never sends those codes. If a design must show something safe for invalid input, such as a blank display, those rows stop being don't-cares and the equations get larger. That is the trade-off: don't-cares buy smaller logic, in exchange for undefined behaviour on inputs that should not happen.

Going further

  • Hex digits. To show A to F as well, all 16 rows become specified and the don't-cares disappear. Try writing the table for A, b, C, d, E, F and re-simplify.
  • Active-low displays. A common-anode display lights a segment on 0. Invert every output, or draw the K-maps for the zeros instead.
  • Blanking. Add a fifth input BI (blanking input) that forces all segments off when set. Each output gains an AND with BI'.
  • Gate count. Count the literals and gates in your equations and compare with the canonical sum of minterms. Seven shared sub-terms, like B'D' and CD', can be built once and reused in several outputs.
  • Real chips. The 7447 and 7448 chips from the TTL family are exactly this decoder, with blanking and lamp-test inputs.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Why are the input codes 10 to 15 treated as don't-cares in this decoder?

    A BCD digit is 0 to 9. Because the codes 10 to 15 never reach the decoder, any output for them is acceptable, and the K-map groups may use them as 1s to get larger groups.
  2. 2. How many Boolean functions does the decoder need, and of how many variables?

    There is one output per segment, a through g, and each is a function of the four input bits A, B, C and D.
  3. 3. Segment c is on for every digit except 2. Which expression is correct?

    c is 0 only when B=0, C=1 and D=0. The complement of B'CD' is B + C' + D by De Morgan's theorem.
  4. 4. Why test a hand-simplified design in code?

    Grouping mistakes are easy to make by hand. Checking every specified input row against the truth table catches them immediately.

Summary

  • A seven-segment decoder maps a 4-bit BCD digit to seven segment signals a to g.
  • Each segment is its own Boolean function, simplified with a K-map.
  • The unused codes 10 to 15 are don't-cares, which let groups grow and make the equations smaller.
  • Simplified results can be checked exhaustively, because four inputs mean only sixteen rows.
  • Unspecified rows can show anything, so a design that must handle invalid input needs those rows specified.

Next: Project: A Logic Circuit Simulator.