Beruflich Dokumente
Kultur Dokumente
Objective
This lab provides an opportunity to learn about the use of a microcontroller (MCU) and its inter-
facing to external devices. We will use ARM Cortex-M4F based Stellaris LM4F120 LaunchPad
to drive a 7-segment display.
A 7-Segment display is a useful electronic component use to produce numeric, alphabetic and
some non-alphabetic symbols using a specific arrangement of LEDs as shown in Figure 8.1.
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
66
67
common-cathode type. Segment intensity is dependent on the current flow and should not
exceed the limit of the segment.
Characters DP G F E D C B A Hexadecimal
0 0 0 1 1 1 1 1 1 3F
1 0 0 0 0 0 1 1 0 06
2 0 1 0 1 1 0 1 1 5B
3 0 1 0 0 1 1 1 1 4F
4 0 1 1 0 0 1 1 0 66
5 0 1 1 0 1 1 0 1 6D
6 0 1 1 1 1 1 0 1 7D
7 0 0 0 0 0 1 1 1 07
8 0 1 1 1 1 1 1 1 7F
9 0 1 1 0 1 1 1 1 6F
A 0 1 1 1 0 1 1 1 77
B 0 1 1 1 1 1 0 0 7C
C 0 0 1 1 1 0 0 1 39
D 0 1 0 1 1 1 1 0 5E
E 0 1 1 1 1 0 0 1 79
F 0 1 1 1 0 0 0 1 71
Figure
To control four 7-segment displays, 8.3: 7 Segment
multiplexing can Decoder
duces Table
the illusion that all four 7-segment displays are
reduce the number of GPIO pins required. turned on.
In this setup, the four multiplexed seven-segment dis-
plays are turned on one at a time to output the appro-
priate display. Because of the visual phenomenon
known as persistence of vision, rapid switching of the
seven-segment display can appear as if all four dis-
EE/CME 392 Laboratory 4-2
PB4 PE 1 PC7 PB 6
PA5 PE 2 PD6 PA 4
PA6 PE 3 PD7 PA 3
In this experiment, we will program the LaunchPad and four-digit 7-segment display module
to display UOFS. In addition, when SW1 is pressed, the display is to flash the letters H,
E, L, O 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. The
display power pins are connected directly to VBUS and GND of J3 On the expansion board.
The experiment uses C language to program the MCU. A program for this task is included in
L, L, urned
off with a
Note caref 2 and
connect t ent 69
display now,
you may the
the lab
MCU.manual.
Us The display latches are connected to PA2-PA5 and the data pins areplish
connected
the task. Using the Latch Enable (LE) pin, your program can update the displays are
to PB0-PB7. digits one
connected splay
at a digits
time.one
5V
3.3V VBUS
(5V)
4
VDD
VDD
PA2 DIG1
PA3 DIG2
3
PA4 DIG3
PA5 DIG4
PB0 A
LM4F120 PB1 B
.. C Q7SD
LaunchPad .. D
.. E
F
..
2
G
PB7 DP
GND
GND
1
SW1
PF4
GND
Part 1c
In this expe n in
Fig. 2). T
Source Code d.
For a full
LM4F of
Consult the datasheet for the proper understanding of this code.
registers will
use only o the
1 #d e corres
f i n e SYSCTL RCGCGPIO R ( ( ( v o l a t i l e u n s i g n e d l o n g ) 0 x400FE608
The ))
2
3 #d e f i n e GPIO PORTB DATA R ((( volatile unsigned long 3
) 0x400053FC ))
4 #d e f i n e GPIO PORTB DIR R ((( volatile unsigned long ) 0 x40005400 ) )
5 #d e f i n e GPIO PORTB AFSEL R ((( volatile unsigned long ) 0 x40005420 ) )
6 #d e f i n e GPIO PORTB DEN R ((( volatile unsigned long ) 0 x4000551C ) )
7 #d e f i n e GPIO PORTB PCTL R ((( volatile unsigned long ) 0 x4000552C ) )
8
9 #d e f i n e GPIO PORTA DATA R ((( volatile unsigned long ) 0x400043FC ) )
10 #d e f i n e GPIO PORTA DIR R ((( volatile unsigned long ) 0 x40004400 ) )
11 #d e f i n e GPIO PORTA AFSEL R ((( volatile unsigned long ) 0 x40004420 ) )
12 #d e f i n e GPIO PORTA DEN R ((( volatile unsigned long ) 0 x4000451C ) )
13 #d e f i n e GPIO PORTA PCTL R ((( volatile unsigned long ) 0 x4000452C ) )
14
15 #d e f i n e GPIO PORTF DATA R ((( volatile unsigned long ) 0x400253FC ) )
16 #d e f i n e GPIO PORTF DIR R ((( volatile unsigned long ) 0 x40025400 ) )
17 #d e f i n e GPIO PORTF AFSEL R ((( volatile unsigned long ) 0 x40025420 ) )
18 #d e f i n e GPIO PORTF DEN R ((( volatile unsigned long ) 0 x4002551C ) )
19 #d e f i n e GPIO PORTF PCTL R ((( volatile unsigned long ) 0 x4002552C ) )
70CHAPTER 8. PARALLEL INTERFACING: INTERFACING SEVEN SEGMENT DISPLAY
67
68 GPIO PORTF PCTL R &= 0xFFF0FF0F ;
69 GPIO PORTF AFSEL R &= 0 x12 ;
70 GPIO PORTF DEN R |= 0 x12 ;
71 GPIO PORTF DIR R |= 0 x02 ;
72 GPIO PORTF PUR R |= 0 x10 ;
73
74 }
75
76 // o t h e r f u n c t i o n s
77 v o i d w a i t f o r k e y ( v o i d ) {
78
79 w h i l e (GPIO PORTF DATA R & 0 x10 ) ; // w a i t f o r SW1 p r e s s , p o l l low
80 GPIO PORTF DATA R |= 0 x02 ; // RED on , make PF1 h i g h
81 delay (1000000) ;
82 GPIO PORTF DATA R &= 0 x02 ; // RED o f f , make PF1 low
83 delay (1000000) ;
84 }
85
86 // d i s p l a y s UOFS on d i s p l a y board
87
88 v o i d d i s p l a y u o f s ( v o i d ) {
89 w h i l e (GPIO PORTF DATA R & 0 x10 )
90 {
91
92 GPIO PORTA DATA R = 0xFF ;
93 GPIO PORTB DATA R = l u t u o f s [ 0 ] ;
94 GPIO PORTA DATA R = SEG 1 ;
95 delay (10000) ;
96
97
98 GPIO PORTA DATA R = 0xFF ;
99 GPIO PORTB DATA R = l u t u o f s [ 1 ] ;
100 GPIO PORTA DATA R = SEG 2 ;
101 delay (10000) ;
102
103
104 GPIO PORTA DATA R = 0xFF ;
105 GPIO PORTB DATA R = l u t u o f s [ 2 ] ;
106 GPIO PORTA DATA R = SEG 3 ;
107 delay (10000) ;
108
109 GPIO PORTA DATA R = 0xFF ;
110 GPIO PORTB DATA R = l u t u o f s [ 3 ] ;
111 GPIO PORTA DATA R = SEG 4 ;
112 delay (10000) ;
113 }
114 }
72CHAPTER 8. PARALLEL INTERFACING: INTERFACING SEVEN SEGMENT DISPLAY
115
116 // d i s p l a y s HELO on d i s p l a y board
117
118 v o i d d i s p l a y h e l o ( v o i d ) {
119 i n t i =0;
120 w h i l e ( i <100)
121 {
122 GPIO PORTA DATA R = 0xFF ;
123 GPIO PORTB DATA R = l u t h e l l o [ 0 ] ;
124 GPIO PORTA DATA R = SEG 1 ;
125 delay (10000) ;
126
127 GPIO PORTA DATA R = 0xFF ;
128 GPIO PORTB DATA R = l u t h e l l o [ 1 ] ;
129 GPIO PORTA DATA R = SEG 2 ;
130 delay (10000) ;
131
132 GPIO PORTA DATA R = 0xFF ;
133 GPIO PORTB DATA R = l u t h e l l o [ 2 ] ;
134 GPIO PORTA DATA R = SEG 3 ;
135 delay (10000) ;
136
137 GPIO PORTA DATA R = 0xFF ;
138 GPIO PORTB DATA R = l u t h e l l o [ 4 ] ;
139 GPIO PORTA DATA R = SEG 4 ;
140 delay (10000) ;
141 i ++;
142 }
143 }
144
145 v o i d d e l a y ( u n s i g n e d l o n g v a l u e ) {
146 unsigned long i ;
147 f o r ( i = 0 ; i < v a l u e ; i ++) ;
148 }
149
150 i n t main ( v o i d ) {
151
152 init gpio () ;
153
154 while (1) {
155 display uofs () ;
156 w a i t f o r k e y ( ) ; // p o l l i n g SW1 (PF4)
157 display helo () ;
158 }
159 }