displaying a 7-segment led and flashing an led array

advertisement
611 37100 Principles and Applications of Microprocessors
Department of Bio-Industrial Mechatronics Engineering
National Taiwan University
LABORATORY 10:
DISPLAYING A 7-SEGMENT LED AND FLASHING AN
LED ARRAY
NAME:
STUDENT ID#:
Objectives
Learn how to:
z
Program the 8255 to show digits on a 7-segment LED.
z
Program both the 8255 and 8279 in order to accept keypad inputs from 0 to F and
display it on a 7-segment LED.
z
Program the 8255 to flash an LED array.
Part 1: Displaying a 7-Semgent LED from keypad inputs
The 7-segment LED display can be found in many displays such as microwave or fancy
toaster ovens and occasionally in non-cooking devices. It is composed of 7 LEDs that are
fabricated in one case to make a convenient device for displaying numbers and some letters.
Figure L10.1 shows a typical 7-segment LED display with its pin layout.
The 7-segment LED shown in Figure L10.1 is a common anode LED display. This means
that the positive leg of each LED is connected to a common point which is pin 3 in this case.
Each LED has a negative leg that is connected to one of the pins of the device. To make it
work, you need to connect pin 3 to +5 volts. Then to make each segment light up, connect
the ground pin to ground. A resistor is required to limit the current. Rather than using a
resistor from each LED to ground, you can just use one resistor from Vcc to pin 3 to limit
the current.
Figure L10.1
A 7-segment LED display and its pin layout.
【LAB10-1】
611 37100 Principles and Applications of Microprocessors
Department of Bio-Industrial Mechatronics Engineering
National Taiwan University
Table L10.1 provides the information that is needed to display digits from 0 to 9 and the
letters A, b, C, d, E, and F. '0' means that pin is connected to ground and '1' means that pin is
connected to Vcc.
Table L10.1 Logic states of 7-segment LED to display different digits or letters.
a (Pin 1)
b (Pin 10)
c (Pin 8)
d (Pin 6)
e (Pin 5)
f (Pin 2)
g (Pin 9)
0
0
0
0
0
0
0
1
1
1
0
0
1
1
1
1
2
0
0
1
0
0
1
0
3
0
0
0
0
1
1
0
4
1
0
0
1
1
0
0
5
0
1
0
0
1
0
0
6
0
1
0
0
0
0
0
7
0
0
0
1
1
1
1
8
0
0
0
0
0
0
0
9
0
0
0
1
1
0
0
A
0
0
0
1
0
0
0
b
1
1
0
0
0
0
0
C
0
1
1
0
0
0
1
d
1
0
0
0
0
1
0
E
0
1
1
0
0
0
0
F
0
1
1
1
0
0
0
Figure L10.2 shows the 7-segment LED decoder circuit. With this information we can
design assembly instructions to display different digits or letters on the 7-segment LED. For
example, the instruction to display ‘1’ on the 7-segment LED is:
OUT
3FF0, F9
To avoid showing the consecutive digits from 0 to F too quickly, we need to insert time
delay before outputting the next digit on the 7-segment LED. This can be accomplished by
writing a time delay loop as follows:
MOV
CX, 0A000H
LOOP $
【LAB10-2】
611 37100 Principles and Applications of Microprocessors
Department of Bio-Industrial Mechatronics Engineering
National Taiwan University
Figure L10.2
The 7-segment LED decoder circuit
Here we will begin our practice of displaying digits or letters on a 7-segment LED with a
simple program. We will analyze, run, and modify the program. Check off each step as it is
completed.
Check
Step
1.
Procedure
Examine the data segment and constant definitions in the program
L10P1.ASM.
a. How many digits does the program generate? ____________________
b. What is the name of the repeat count that is used to set the duration
between digits? ___________________
Find the value assigned to this constant in the program. _____________
2. Examine the part of the program in L10P1.ASM.
What is the address of FND? __________
a. What does the instruction sequence that follows do?
J2:
MOV
AL, [SI]
OUT
DX, AL
MOV
CX, 0A000H
LOOP $
INC
SI
DEC
BL
JNZ J2
b. Is this FND a common cathode or anode LED? __________
3. List the 16-bit words corresponding to the display of each digit from 0 to F.
____________________________________________________________
____________________________________________________________
____________________________________________________________
____________________________________________________________
【LAB10-3】
611 37100 Principles and Applications of Microprocessors
Department of Bio-Industrial Mechatronics Engineering
National Taiwan University
4.
Do the following steps to generate a downloadable hex format file and
download it through RS-232.
C:\> MASM
(↵)
Enter L10P1
C:\> LINK
(↵)
Enter L10P1
5.
6.
C:\> EXE2BIN L10P1
(↵)
C:\> BIN2HEX (↵)
Enter L10P1.BIN
Use debug program to trace L10P1.EXE and describe what you see.
____________________________________________________________
____________________________________________________________
Modify the program to show only even digits. Reassemble, relink, and
generate L10P1A.EXE. Download the new program to MTS-86C and
verify the program that it works correctly. Describe the difference between
what was seen in step 4 and what you now see. Hand in your program
listing with this lab report.
____________________________________________________________
____________________________________________________________
Part 2: Scan a key from the keypad and display it on a 7-segment LED
In this part of the lab, we will learn to read inputs from a keypad and display the
corresponding key that is pressed on a 7-segment LED display. You will need to write an
assembly program that will determine which key has been pressed on the key pad. The
program will then display the corresponding character by configuring the output port
correctly (the 7-segment displays). A schematic diagram is provided below to show
connections needed to implement this lab. To do this, we will briefly introduce the
fundamentals of a keypad and we will also show how an 8279 is used to interface a keypad.
The circuit of 8279 is shown in Figure L10.3. In order to scan the keypad, the 8279 outputs
a nibble to force one (only one) of the columns low and then reads the rows to see if any key
in that column have been pressed. The rows are pulled up by the internal weak pull-ups in
the 8279 ports. Consequently, as long as no key is pressed, the 8279 detects a logic high on
each of the pins attached to the keypad rows. The nibble driven onto the columns always
contains only a single 0. The only way that the 8279 can find a 0 on any row pin is when the
keypad button to be pressed. In that case, a logic 0 will be read on the corresponding column
【LAB10-4】
611 37100 Principles and Applications of Microprocessors
Department of Bio-Industrial Mechatronics Engineering
National Taiwan University
line. The 8279 identifies which column is at a 0-level and which row reads 0, allowing it to
determine which key is pressed. For the keypad, the pins from left to right are: R1, R2, R3,
R4, C1, C2, C3, C4.
Figure L10.3
Check
Step
1.
Keypad interface with 8279
Procedure
View the file L10P2.ASM with an editor. What are the contents of the data
table in the program?
2. What is the address of 8279?
3. What does the instruction sequence that follows do?
_____________________________________________________________
CNTR79 EQU
0FFEAH
MOV
DX, CNTR79
MOV
AL, 0
OUT
DX, AL
MOV
AL, 39H
OUT
DX, AL
4. What happens if skipping the below instructions in LP10P2.ASM?
_____________________________________________________________
LOOP1: IN
AL, DX
TEST
AL, 7
JZ
LOOP1
5. Write a new program, L10P2A.ASM, modified from the program
L10P2.ASM, to scan the keypad and display digits only from 0 to F on the
7-segment LED. Hand in your program listing with this lab report.
【LAB10-5】
611 37100 Principles and Applications of Microprocessors
Department of Bio-Industrial Mechatronics Engineering
National Taiwan University
Part 3: A Simple Program to flash an LED array
The objective of this part of the lab is to know how to flash an LED array through 8255
interface. Figure L10.4 shows the interface circuit for the LED array.
Figure L10.4
Check
Step
1.
Interface circuit for an LED array
Procedure
View the file L10P3.ASM with an editor. What are the addresses of the
control register, port A and port B?
2. What is the operation mode of 8255?
3. What does the instruction sequence that follows do?
CNT3
EQU
3FD6H
APORT3
EQU
3FD0H
BPORT3
EQU
3FD2H
MOV
AL, 90H
MOV
DX, CNT3
OUT
DX, AL
J1:
MOV
DX, APORT3
IN
AL, DX
NOT
AL
MOV
DX, BPORT3
OUT
DX, AL
JMP
J1
4. Why is the purpose of the instruction 'NOT AL’?
5. Write a new program, L10P3A.ASM, to light the LED array with different
flashing pattern. The assembly program will flash the LED array
continuously at approximately 1Hz. You need to implement a simple loop
in the program that delays for 500 ms (half a second) with the LED on, and
then delays for another 500 ms with the LED off. Thus, the LED flashes at
1 Hz! Hand in your program listing with this lab report.
【LAB10-6】
Download