In the previous entry we created a first version of a 4 bit register, the QuadDFlipFlop. The content of the register was displayed in binary using 4 LED's. Also, remember how we can convert between decimal, binary and hex numbers:
We can use four LED's to display a four bit number. There is also a nice component, called a seven segment display, that we can use as an alternative to four LED's.
Seven segment display
Curated answer from Grok on seven segment display:
Seven-Segment Display Basics
- Segments: Labeled a–g (plus dp for decimal point, optional).
- a: Top
- b: Top-right
- c: Bottom-right
- d: Bottom
- e: Bottom-left
- f: Top-left
- g: Middle
- Types:
- Common Cathode: All segment cathodes tied together to ground; apply 5V to anodes (a–g) to light segments.
- Common Anode: All anodes tied to 5V; ground cathodes to light segments.
- We’ll assume common cathode (easiest with 5V logic); adjust if yours is common anode.
A seven segment display has 10 pins at the back, five at the top (g f cm a b) and five at the bottom (e d cm c dp). This picture shows the pins and the segments:
The pins a-g are connected to the corresponding segments. For example, segment "a", the top one, is controlled by the pin labeled "a", the fourth pin at the top. "cm" is the common cathode/anode and "dp" controls the "dot" at the bottom right.
Here is the design of common cathode and common anode:
If you have a common anode display, hook up cm to +5V (trough a resistor). To turn on segment "a", ground the pin labeled "a".
If you have a common cathode display, hook up cm to ground (trough a resistor). To turn on segment "a", connect the pin labeled "a" to +5V.
- If the middle segment turns on when you connect "g" (the first upper pin) to ground and the resistor to +5V: common anode.
- If the middle segment turns on when you connect "g" to +5V and the resistor to ground: common cathode.
Driving a seven segment display
Next, I want the display to show a four bit binary number in hex, 0010 to 2, 1110 to E and so on. Grok's curated answer:
Converting a 4-bit binary number (0 to 15 in decimal, 0 to F in hex) to drive a seven-segment display involves translating the binary input into signals that light up the correct segments (a, b, c, d, e, f, g) to show the corresponding digit. A seven-segment display has 7 individual LED segments arranged to form numbers and some letters, and we’ll use it to display 0–9 and A–F (for hex). Here’s how to do it on a breadboard, tying it to your 4-bit register setup.
Step 1: Define the Mapping
Each 4-bit binary number (0000 to 1111) corresponds to a digit (0–F). You need to light specific segments for each:
Binary | Hex | Decimal | Segments (a-g) |
---|---|---|---|
0000 | 0 | 0 | a, b, c, d, e, f |
0001 | 1 | 1 | b, c |
0010 | 2 | 2 | a, b, d, e, g |
0011 | 3 | 3 | a, b, c, d, g |
0100 | 4 | 4 | b, c, f, g |
0101 | 5 | 5 | a, c, d, f, g |
0110 | 6 | 6 | a, c, d, e, f, g |
0111 | 7 | 7 | a, b, c |
1000 | 8 | 8 | a, b, c, d, e, f, g |
1001 | 9 | 9 | a, b, c, d, f, g |
1010 | A | 10 | a, b, c, e, f, g |
1011 | B | 11 | c, d, e, f, g |
1100 | C | 12 | a, d, e, f |
1101 | D | 13 | b, c, d, e, g |
1110 | E | 14 | a, d, e, f, g |
1111 | F | 15 | a, e, f, g |
Step 2: Hardware Approach
You’ll convert your 4-bit register’s outputs (Q0–Q3) into 7 signals (a–g) to drive the display. Here are two practical methods:
Option 1: Use a BCD-to-Seven-Segment Decoder (74LS47 or 74HC4511)
Option 2: Custom Logic with Gates
For full 0–F display, design combinational logic for each segment using your 4-bit inputs (Q0–Q3). This is more work but educational.
- Inputs: Q3 (8), Q2 (4), Q1 (2), Q0 (1).
- Outputs: a, b, c, d, e, f, g (1 = on, 0 = off).
- Logic Equations (from truth table):
- a = Q3̅Q2̅Q1̅Q0̅ + Q3̅Q2̅Q1Q0̅ + Q3̅Q2Q1̅Q0 + Q3̅Q2Q1Q0 + Q3Q2̅Q1̅Q0 + Q3Q2Q1Q0̅ + Q3Q2Q1Q0
- b = Q3̅Q2̅Q1̅Q0 + Q3̅Q2̅Q1Q0 + Q3̅Q2Q1Q0̅ + Q3Q2̅Q1̅Q0 + Q3Q2̅Q1Q0 + Q3Q2Q1̅Q0
- c = Q3̅Q2̅Q1Q0̅ + Q3̅Q2Q1Q0 + Q3Q2̅Q1̅Q0 + Q3Q2Q1̅Q0 + Q3Q2Q1Q0
- d = Q3̅Q2̅Q1̅Q0 + Q3̅Q2Q1̅Q0 + Q3Q2̅Q1Q0̅ + Q3Q2Q1̅Q0 + Q3Q2Q1Q0
- e = Q3̅Q2̅Q1̅Q0 + Q3Q2̅Q1̅Q0 + Q3Q2̅Q1Q0 + Q3Q2Q1̅Q0 + Q3Q2Q1Q0
- f = Q3̅Q2̅Q1̅Q0 + Q3̅Q2Q1̅Q0 + Q3Q2̅Q1̅Q0 + Q3Q2Q1̅Q0 + Q3Q2Q1Q0
- g = Q3̅Q2̅Q1̅Q0 + Q3̅Q2Q1Q0̅ + Q3Q2̅Q1̅Q0 + Q3Q2Q1̅Q0 + Q3Q2Q1Q0
- Implementation:
- Use 74HC00 (NAND), 74HC08 (AND), 74HC32 (OR) gates to build each equation.
- Example: "a" needs 7 AND gates (for each term) feeding an OR gate.
- Total: ~20–30 gates (impractical without a PLD).
-end-
74LS47
The simple choice is to use the 74LS47:
You connect the four binary inputs to A, B, C, and D, where A is the lowest bit (Q0) and D the highest (Q3). The output pins a-g are the connected to the corresponding pins on the display (not sure what pins 3,4, and 5 do).
Grok's answer above allows us to figure out how this IC works internally.
Whether the output pin "a" should be high can be determined from the input pins Q3-Q3 according to the logic equations above. We can simplify the formula for a:
a = t1 + t2 + t3 + t4 + t5 + t6 + t7
where t1 = Q3̅Q2̅Q1̅Q0̅ and so on (the bar on top means inverted Q). "Product" in a logical equation means "AND". Therefore, we can get t1 using a four input AND gate. We hook up the four inverted Q's to the input pins and the output pin is t1.
Another four input AND gate will give us t2 = Q3̅Q2̅Q1Q0̅ , and so on. Sum "+" in a logical equation means "OR". Therefore, we connect t1..t7 to a seven input OR gate. The output of this OR gate is precisely "a".
Example: If Q = 0000 (Q = 0) then t1 = 1 and a = 1. This is correct, segment "a", the top segment, should be on when Q = 0. If Q = 0001 (Q = 1) then all t1..t7 are 0, and a = 0. This too is correct, segment a should be off when Q = 1.
There are obviously more clever ways of designing your own 74LS47 using basic gates. But the point is that it can be built from basic gates, it contains to "mysteries". I guess it could be fun to build the 74LS47 from basic gates, but I am not going to do that.
ACEL Seven segment decoder
Acel has
- SevenSegmentDecoderAnode to be used with a common anode display. Connect "cm" through a resistor and to +5V.
- SevenSegmentDecoderCathode to be used with a common cathode display. Connect "cm" through a resistor and to ground.
- Input pins Q[3], Q[2], Q[1], Q[0] where Q[3] is the highest bit (these corresponds to the pins D, C, B, A on 74LS47)
- Output pins S[0], ... , S[6] (these corresponds to the pins a..g on 74LS47)
Here is an example with a common anode display. Four DIP-switches are connected to the input pins:
You can also try this out on Wokwi, project "Seven segment decoder".