Tiva Lab 03: Seven Segment Display

Objective

  • Learn how to use a seven-segment display
  • Learn how to use an array to store the predefined values

Required Reading Material

Background Information

In this lab, you are going to interface a seven segment display to Tiva LaunchPad. The display counts from 0 ~ F and resets itself to zero. Before going further, let us first discuss about seven segment displays.

Seven Segment Display

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

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

7SegDisplay 01 s7SegDisplay 02 s

There are mainly two types of seven segment display available. In a simple LED package as shown on 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, in order to match standard IC sockets.

In general, common anode displays are more popular than common cathods displays, since logic circuits can sink more current than they can source.

How to display an number on the seven segment display?

Depending upon which character will be displayed, the particular set of LEDs is forward biased.

Display a "0"
Common Cathode 0

To display the numerical digit "0" on the display as shown in figure above, the LED segments corresponding to a, b, c, d, e and f must be lit up.
For common cathode display, these pins must be connected to power, and for common anode display, these pins must be connected to ground.

Display a "1"
Common Cathode 1

To display the numerical digit "1" on the display as shown in figure above, the LED segments corresponding to b, c must be lit up.
For common cathode display, these pins must be connected to power, and for common anode display, these pins must be connected to ground.


Displaying Letters

7 segments Indicator

A single byte can encode the full state of a 7-segment-display. The most popular bit encodings are gfedcba and abcdefg, where each letter represents a particular segment in the display. In the gfedcba representation, a byte value of 0x06 would (in a common anode circuit) lit up segments 'c' and 'b', which would display a '1'.

Hexadecimal digit can be displayed on a seven-segment display. A combination of uppercase and lowercase letters is used for letters 'A' to 'F'; this is done in order to obtain a unique, unambiguous shape for each hexadecimal digit (otherwise, a capital 'D' would look identical to a '0' and a capital 'B' would look identical to an '8'). Also the digit '6' must be displayed with the top bar lit to avoid ambiguity with the lowercase letter 'b'.

The folowing table applies common cathode seven segment display device. If you are using a common anode, the values in the table must be inverted.

Table 1: Seven Segment Display Truth 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 0                  
3 SevenSegment 080 s 0                  
4 SevenSegment 103 s 0                  
5 SevenSegment 110 s 0                  
6 SevenSegment 126 s 0                  
7 SevenSegment 008 s 0                  
8 SevenSegment 128 s 0                  
9 SevenSegment 112 s 0                  
A SevenSegment 120 s 0                  
B SevenSegment 125 s 0                  
C SevenSegment 058 s 0                  
D SevenSegment 095 s 0                  
E SevenSegment 122 s 0                  
F SevenSegment 114 s 0                  

When you connect 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. The 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.

Required Components List

Resistor 64 220 Ω Resistor x 8
7SegDisplay 64 7-Segment Display x 1
breadboard s Breadboard x 1

 

Circuit / Schematic Diagram

The circuit diagram for connecting a common cathode seven segment display to the TI Tiva microcontroller port is shown below. The microcontroller I/O pins source the current required for the segment LEDs. The current limiting resistors connected in series between the microcontroller pina and segment LEDs are 220ohm each. Segments a ~ g and dp are driven through GPIO output ports.

Procedure

Lab Experiment

Wire the circuit for the 7-segment display to the GPIO Ports on the breadboard, using eight current limiting resistors. Make sure the power is disconnected when wiring up your breadboard.

The predefined hexadecimal encoding values need to be shifted to the corresponding bit in order to light up the correct segment LED on different Ports.

Write a C code to have your display count up from 0 to F (and then rolls over to 0 again), with each digit displayed for one second.

  1. Modify your code, add SW1 function into your project.
  2. After power reset, the counter is STOP, and display '0' on the 7-Segment Display.
  3. When the user presses SW1, the counter START to count up from 0 to F with 1 sec interval, and rolls over to 0 again.
  4. User can press SW1 to PAUSECONTINUE the counter.

You can use the following flowchart or finite state machine to implement the code:

LabExp01 s
Figure: The Polling Solution
LabExp02 s
Figure: F.S.M Solution

Questions

  1. What type of seven segment display you used in this lab?
  2. Complete the table 1 which shows which segments must be illuminated to display the hex digits 0..F.
  3. If you used a common anode (CA) 7-segment display instead of a common cathode (CC) one, what change would you have to make in the wiring and the code?
  4. In this lab, we use eight resistors for each LED on 7-segment display unit. Instead of using eight resistors, can you just use one 220 ohm resistor connected to the common ground of the unit, and have the equivalent circuit? Explain why or why not.


Exercises