Download as pdf or txt
Download as pdf or txt
You are on page 1of 7

Experiment 8

Parallel Interfacing: Interfacing Seven


Segment Display

Objective

This lab provides an opportunity to learn about the use of a microcontroller (MCU) and inter-
facing it to external devices. The lab uses the Stellaris LM4F120 LaunchPad board, that has
an ARM Cortex-M4F (LM4F120H5QR) MCU on it, and C language programming to drive a
7-segment display.

Seven Segment Display Construction

Seven segment display is a useful electronic component used to produce numeric, alphabetic and
some non-alphabetic symbols using a specific arrangement of LEDs as shown in Figure 8.1

7 Segment LED Display

A seven segment display consists of seven LEDs arranged in the form of a squarish ‘8’ slightly
inclined to the right and a single LED as the dot character. Different characters can be displayed
by selectively glowing the required LED segments. Seven segment displays are of two types,
common cathode and common anode. In common cathode type, the cathode of all LEDs are
tied together to a single terminal which is usually labeled as ‘com’ and the anode of all LEDs
are left alone as individual pins labeled as a, b, c, d, e, f, g & dot. In common anode type, the
anode of all LEDs are tied together as a single terminal and cathodes are left alone as individual
pins. Both the configurations are shown in Figure 8.2

In this experiment, a GPIO port on the LM4F120H5QR MCU transmits 8 bits of data. These
bits are applied to the seven-segment display to cause it to illuminate the appropriate segments
to display the proper number or character. The seven segment used in this experiment is of

74
75

Common Anode and Common Cathode Configurations

common-cathode type. Segment intensity is dependent on the current flow and should not
exceed the limit of the segment.

Digit Drive Pattern

Digit drive pattern of a seven segment LED display is simply the different logic combinations
of its terminals. For a certain character, a combination of LED ON and LED OFF is generated
to display the character for a short period of time. The pattern is loaded alternately to display
other characters. For example, to display the number 2, LEDs a, b, d, e, and g are illuminated.
Table 8.3 provides the display pattern for numbers(0-9) and characters A through F.

Characters DP G F E D C B A Hexadecimal
0 1 1 0 0 0 0 0 0 0xC0
1 1 1 1 1 1 0 0 1 0xF9
2 1 0 1 0 0 1 0 0 0xA4
3 1 0 1 1 0 0 0 0 0xB0
4 1 0 0 1 1 0 0 1 0x99
5 1 0 0 1 0 0 1 0 0x92
6 1 0 0 0 0 0 1 0 0x82
7 1 1 1 1 1 0 0 0 0xF8
8 1 0 0 0 0 0 0 0 0x80
9 1 0 0 1 0 0 0 0 0x90
A 1 0 0 0 1 0 0 0 0x88
B 1 0 0 0 0 0 1 1 0x83
C 1 1 0 0 0 1 1 0 0xC6
D 1 0 1 0 0 0 0 1 0xA1
E 1 0 0 0 0 1 1 0 0x86
F 1 0 0 0 1 1 1 0 0xs8E

7 Segment Decoder Table


Part 1a – Starter project (< 1 hour)
Obtain from
76CHAPTER 8. the technicians INTERFACING:
PARALLEL one Stellaris® LM4F120 LaunchPad and
INTERFACING one four-digit
SEVEN SEGMENT 7-segment
DISPLAY
display module. Use the USB cable to connect the lab computer’s USB port to the Power/ICDI
micro-USB port at the top of the LaunchPad. Make sure the slide switch in the top left corner is
in the right hand
Multiplexing theposition.
Seven Segments
In order to verify the LaunchPad circuit function and to become familiar with loading a program
into thefour
To control LaunchPad, youdisplays,
7-segment should run the starter project
multiplexing is provided
can reduce the on the course
number website.
of GPIO pinsUsing
required.
the lab computers in 2C61 or 2C80, download the project (starter.zip), unzip it and run the
In this setup, the four multiplexed seven-segment displays are turned on one at a time to output
uVision4 project named “start_0.uvproj”. Within uVision4, go to “Projects > Options for
Target”. Under
the appropriate the “utilities”
display. Becausetab,
of make sure that
the visual Stellaris ICDI
phenomenon is listed
known as the target of
as persistence driver for rapid
vision,
switching of the seven-segment display can appear as if all four displays are turned on.of
flash programming. Close the window and “Load” (download) the code into the flash memory
the MCU. To program the LaunchPad’s MCU, the Power Select Switch must remain in “Debug”
position and the USB cable must remain connected since the LaunchPad is powered from it. For
other power options, consult p.11 of the user manual [1]. Press the RESET button (must do after
every download)
Launchpad then press SW1 (active low) and observe the LED flashing (active high).
Interface
Now study the starter code (starter_0.c) and the comments after every line – it will help you
better understand the code, syntax and configuration of LM4F120 MCU. The code is to simply
Beforeturn
youonbuild your circuit,
the onboard red, blueyou
andshould carefully
green LEDs note the
in sequence non-sequential
when pin-out
the switch (SW1) diagram of
is pressed.
The switch and
the LaunchPad LEDsinare
shown all connected
Figure to Port F. the LM4F120H5QR MCU has 43 GPIOs, only
8.4. Although
35 of LaunchPad Interface:
them are available Before the
through youLaunchPad.
go to the nextThey
section
are:and build ofyour
6 pins circuit,
Port you should8 pins
A (PA2-PA7),
carefully
of Port note the non-sequential
B (PB0-PB7), 4 pins of Portpin-out diagram of the
C (PC4-PC7), LaunchPad
6 pins of Portshown in Fig. 1. Although
D (PD0-PD3, PD6-PD7), 6
the LM4F120H5QR MCU has 43 GPIO, only 35 of them are available through the LaunchPad.
pins of Port
They are:E6(PE0-PE5) and
pins of Port A 5 pins of8Port
(PA2-PA7), F Port
pins of (PF0-PF4). In addition,
B (PB0-PB7), there
4 pins of Port are two ground,
C (PC4-PC7),
6 pinsone
one 3.3V, of Port
5V D (PD0-PD3,
(VBUS), andPD6-PD7),
one reset6pin
pinsavailable
of Port E on
(PE0-PE5), and 5 pins of Port F (PF0-
the LaunchPad.
PF4). In addition, there are two ground, one 3.3V, one 5V (VBUS), and one reset pins available
on the LaunchPad.
Pins PC0-PC3 are left off as they are used for JTAG debugging. Pins PA0-PA1 are also left off
Pinsare
as they PC0-PC3 arecreate
used to left offaasvirtual
they areCOM
used for JTAG
port debugging.
to connect thePins PA0-PA1 are
LaunchPad to also
PC.left off pins
These
as they are used to create a virtual COM port to connect the LaunchPad to PC. These pins should
should not be used for regular I/O purpose.
not be used for regular I/O purpose.
J1 J3 J4 J2

3.3V VBUS PF2 GND

PB5 GND PF3 PB 2

PB0 PD0 PB3 PE 0

PB1 PD1 PC4 PF0

PE4 PD2 PC5 RST

PE5 PD3 PC6 PB 7

PB4 PE 1 PC7 PB 6

PA5 PE 2 PD6 PA 4

PA6 PE 3 PD7 PA 3

PA7 PF1 PF4 PA 2

Fig. 1 Header pins on the LaunchPad (EK-LM4F120XL)


Header Pins on the Launchpad (EK-LM4F120H5QR)
2

Display System Using Seven Segments

In this experiment, we will program the LaunchPad and four-digit 7-segment display module
to display “UOFS”. In addition, after some delay, the display is to flash the letters “H”, “E”,
“L”, “O” and then settle back to “UOFS”.

Note carefully the diagram of the display module. Connect the circuit as shown in Figure 8.5.
The LaunchPad board is sufficient to supply +5V to Vdd of the 7-segment display module
- connect the display power pins directly to VBUS and GND of J3. The experiment uses C
language to program the MCU. Write a program to accomplish the task. You will need to open
display module - connect the display power pins directly to VBUS and GND of J3. For now,
you may omit the pot (required for Part 1c). The experiment uses C language to program the
MCU. Using the code template (provided on the course website), write a program to accomplish
the task. You will need to open a new project on Keil uVision4. Note that display latches are
connected to PA4-PA7. Using the Latch Enable ( LE ) pin, your program can update the display 77
digits one at a time.

3.3V 5V
3.3V VBUS
(5V)

POT

1
VDD
VDD
PB0 D0 (g)
PB1 D1 (f)

2
.. D2 (a)
.. D3 (b)
.. D4 (c)
LM4F120 ..
D5 (d)
D6 (e) Q7SD
LaunchPad PB7 D7 (DP)
PA2 DIG1
PA3 DIG2

3
PA4 DIG3
PA5 DIG4
GND
GND

4
SW1

GND

Fig. 2 Connection to 7-Segment Display


Connection to Seven Segment Display

Part 1c: Analog-to-Digital Converter (optional)


a new project on Sourcery Codebench. Note that display latches are connected to PA4-PA7
In this experiment, we will use one ADC module to sample the voltage across the pot (shown in
and
Fig. 2). the
The data pins
sampled are connected
voltage to PB0-PB7.
will be converted Using
to a hex value the
and Latch Enable
displayed (LE) board.
on the display pin, your program
Forcan
a full resolution,
update i.e., 12-bits,
the display we one
digits will need
at a three
time.7-segment displays.
LM4F120 MCU has two 12-bit ADC modules. Each module is controlled by a number of
registers and offers a variety of options. The module has four sequencers. For simplicity, we will
use only sequencer 3 since it captures only one sample per trigger and stores the sample into the
Source Code
corresponding FIFO (p.755). The sampling rate can be varied from 125 ksps to 1 Msps. The

3
Source code for displaying UOFS is given below. Two files are included here. gpio.h includes
the register definitions and display UOFS displays UOFS. Create new project in Keil and add
both files in it. Build your code and observe the output.

Example 8.1: gpio.h

# d e f i n e SYSCTL_RCGCGPIO_R (∗(( volatile u n s i g n e d l o n g ∗) 0 x400FE608 ) )

# d e f i n e GPIO_PORTB_DATA_R (∗(( volatile u n s i g n e d l o n g ∗) 0 x400053FC ) )


# d e f i n e GPIO_PORTB_DIR_R (∗(( volatile unsigned long ∗) 0 x40005400 ) )
# d e f i n e GPIO_PORTB_DEN_R (∗(( volatile u n s i g n e d l o n g ∗) 0 x4000551C ) )

# d e f i n e GPIO_PORTA_DATA_R (∗(( volatile u n s i g n e d l o n g ∗) 0 x400043FC ) )


# d e f i n e GPIO_PORTA_DIR_R (∗(( volatile unsigned long ∗) 0 x40004400 ) )
# d e f i n e GPIO_PORTA_DEN_R (∗(( volatile u n s i g n e d l o n g ∗) 0 x4000451C ) )

# d e f i n e SEG_1 0 xFB
# d e f i n e SEG_2 0 xF7
78CHAPTER 8. PARALLEL INTERFACING: INTERFACING SEVEN SEGMENT DISPLAY

# d e f i n e SEG_3 0 xEF
# d e f i n e SEG_4 0 xDF
# d e f i n e SEG_OFF 0 xFF

void i n i t _ g p i o ( void ) ;
void display_uofs ( void ) ;
void display_hello ( void ) ;
void delay ( unsigned long value ) ;

Example 8.2: display UOFS.c

/∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗
∗ T h i s p r o g r a m i s w r i t t e n f o r common a n o d e t y p e s e v e n s e g m e n t d i s p l a y ∗
∗ S e v e n s e g m e n t d i g i t s p i n s : PA2 − PA5 ∗
∗ S e v e n s e g m e n t d a t a p i n s : PB0 − PB7 ∗
∗ PortB pins : 76543210 ∗
∗ pgfedcba ∗
∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗
∗/

# include " gpio . h "

/ / L o o k up t a b l e s f o r common a n o d e display
/ / l u t f o r UOFS
c o n s t c h a r l u t _ u o f s [ 4 ] = { 0 xC1 , // U 11000001
0 xC0 , // O 11000000
0 x8E , // F 10001110
0 x92 // S 10010010
};

/ / l u t f o r HELO
const char l u t _ h e l o [ 4 ] = { 0 x89 , //H 10001001
0 x86 , //E 10000110
0 xC7 , //L 11000111
0 xC0 //O 11000000
};

const char seg_select [ ] = { 0 xFB , // SEG_1


0 xF7 , // SEG_2
0 xEF , // SEG_3
0 xDF // SEG_4
};

// i n i t i a l i z a t i o n function for ports


void i n i t _ g p i o ( void ) {
v o l a t i l e unsigned long delay_clk ; / / d e l a y f o r c l oc k , must have 3 sys
clock delay
79

SYSCTL_RCGCGPIO_R | = 0 x 0 3 ;
d e l a y _ c l k = SYSCTL_RCGCGPIO_R ;

GPIO_PORTB_DIR_R | = 0 xFF ;
GPIO_PORTB_DEN_R | = 0 xFF ;

GPIO_PORTA_DIR_R | = 0 x3C ;
GPIO_PORTA_DEN_R | = 0 x3C ;
}

/ / d i s p l a y s UOFS on d i s p l a y b o a r d
void display_uofs ( void ) {

GPIO_PORTA_DATA_R = SEG_OFF ;
GPIO_PORTB_DATA_R = l u t _ u o f s [0];
GPIO_PORTA_DATA_R = SEG_1 ;
delay (10000) ;

GPIO_PORTA_DATA_R = SEG_OFF ;
GPIO_PORTB_DATA_R = l u t _ u o f s [1];
GPIO_PORTA_DATA_R = SEG_2 ;
delay (10000) ;

GPIO_PORTA_DATA_R = SEG_OFF ;
GPIO_PORTB_DATA_R = l u t _ u o f s [2];
GPIO_PORTA_DATA_R = SEG_3 ;
delay (10000) ;

GPIO_PORTA_DATA_R = SEG_OFF ;
GPIO_PORTB_DATA_R = l u t _ u o f s [3];
GPIO_PORTA_DATA_R = SEG_4 ;
delay (10000) ;
}

/ / d i s p l a y s HELO on d i s p l a y b o a r d
void display_helo ( void ) {
int i ;
f o r ( i = 0; i < 5; i ++)
{

GPIO_PORTA_DATA_R = SEG_OFF ;
GPIO_PORTB_DATA_R = l u t _ h e l o [ i ] ;
GPIO_PORTA_DATA_R = s e g _ s e l e c t [ i ] ;
delay (10000) ;
}
}

void delay ( unsigned long value ) {


unsigned long i ;
80CHAPTER 8. PARALLEL INTERFACING: INTERFACING SEVEN SEGMENT DISPLAY

f o r ( i = 0; i < value ; i ++) ;

i n t main ( v o i d ) {
init_gpio () ;

while (1)
display_uofs () ;
// display_helo () ;

You might also like