






Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!







EEE3410 Microcontroller Applications
Laboratory Experiment 5 1
7-segment Display & ADC Controls with 8051
Name Date
Class Class No.
Marks
7-segment Display & ADC Controls
Objectives
To understand the connection of 7-segment display to 8051
To know how to write 8051 assembly program to control 7-segment display
To understand the connection of an ADC to 8051
To know how to write 8051 assembly program to control an ADC to acquire data
Equipment/Components Required
PC compatible computer with Windows XP
MedWin 8051 simulation software.
ADC & 7-segment Display training board with power supply and connection cable
HT1000 89C51 Writer
floppy disk/USB flash disk
Ver Author(s) Date Remark 1.0 KK SIN 9/
2 Experiment 5 Laboratory
A1. The 7-segment LED numeric display
A 7-segment LED numeric display contains 8 LEDs, of which 7 segments are arranged in the shape of the number “8” to display the digits 0-9, and the eighth one is the decimal point (DP). (Ignore the decimal point in this Laboratory.) Basically, it has one common lead (either anode or cathode) which is connected to the power supply, and the remaining 7 individual leads are for each segment.
Segment displays are driven by connecting each segment to a port bit, or they can be driven by decoder/driver IC designed for the purpose. A decoder/driver chip will accept a parallel input from a 8051 port (binary or ASCII) and drive the display to show the corresponding character. The table shows the corresponding connection of the 8 output port bits to the 8 input terminals of display segments.
Output Port bit 7 6 5 4 3 2 1 0 Display segment Dp g f e d c b a
There are two common types of configurations; namely, the common-anode configuration and the common-cathode configuration.
Common-anode configuration – Segment will light up if the output port bit is set LOW. Common-cathode configuration - Segment will light up if the output port bit is set HIGH.
Normally a resistor of 330Ω is connected between each segment terminal and output port bit in order to protect the LED segment.
In this laboratory, you will appreciate how to program the 8051 to control 7-segment LED numeric displays.
a
b
c
d
e
f (^) g
Segment Pattern
Dp h
Common a b c d e (^) f g Dp Common-cathode configuration
Common a b c d e f g Dp Common-anode configuration
4 Experiment 5 Laboratory
Write ( WR ) (Start conversion) WR is also called “start conversion”. It is an active-low input signal. It is used to start the ADC0804 IC for data conversion. With CS =0, if a low-to-high pulse is applied to pin WR , the ADC0804 IC will start converting the analog input value at pin VI+ to an 8-bit digital number. Once data conversion is complete, pin INTR will be set to LOW. Interrupt ( INTR ) (End of conversion) INTR is also called “end of conversion”. It is an active-low output signal. It is usually high but once data conversion is complete, it set to LOW to indicate that the converted data is ready for pick-up. VCC VCC is the +5V power supply to the ADC0804 IC. It can be also used as a reference voltage (VREF) if the pin VREF/2 is open. VREF/ VREF/2 is an input used for reference voltage other than 0-5V range. But if VREF/2 is left open, the analog input voltage will be in the range of 0-5V. Data pins D0-D DB0-DB7 are the digital data output pins, with D7 as the most significant bit (MSB) and D0 as the least significant bit (LSB). They can only be accessed when both CS = and RD is LOW.
A2.2 Digital output of the ADC804 IC In this Laboratory, the VREF/2 pin is left open, i.e. the analog input voltage (VIN) is in the range 0-5V. Because the ADC0804 IC has a resolution of 8 bits, the range is divided into 2^8 =256 steps. Or, we can say that there are 255 quantization levels (0V inclusive).
The step size, or the resolution of the ADC804 IC, is:
step size 8 REF
−
The digital data value (DOUT) of the ADC804 IC is:
step size
EEE3410 Microcontroller Applications
Laboratory Experiment 5 5
e.g. : A 5V is set to the VREF pin of a ADC0804, find the digital value output from the ADC if it converts an analog input voltage of 3.5V. Solution: V 0. 0196 V 255
step size= 5 = ;
178 or 179
OUT =^ = (depends on the accuracy of the ADC)
A2.3. Control of ADC0804 IC to carry out analog-to-digital conversion
Normally ADC0804 IC is interfaced with microcontroller to form a data acquisition system, circuit shown in fig. A2.1. The microcontroller will send out a fixed sequence of control signals to direct the ADC to complete the A/D conversion process and output the converted value.
Fig. A2.2 shows a flowchart gives the steps for signal time issued by a 8051 to control the ADC0804IC Start
Set CS to LOW
Does INTR change to LOW?
Set CS to LOW Set RD to LOW
Read the ready ADC Data by a 8051 input port
N
Y
Set WR to LOW Next return WR to HIGH Then return CS to HIGH
Next return RD to HIGH Then return CS to HIGH
Repea
Fig. A2.2 Flowchart of timing control of ADC
DB DB DB DB DB DB DB DB
VI+
VREF
VI-
CLK
INTR
WR
RD
CS
CLKR
AGND ADC
VCC
8051 Microcontroller
Input bits
Output Control bits
Input analog voltage
Fig. A2.1 Interface of ADC0804 to 8051 microcontroller
EEE3410 Microcontroller Applications
Laboratory Experiment 5 7
A3. ADC & 7-segment Display training board
Figure A3.1 shows the circuit diagram of the ADC & 7-segment Display training board. Port 2, Port bit 3.6 and Port bit 3.2 are connected to the 8-bit output, pin WR and pin INTR of ADC0804 respectively. Port 0 is connected to a common-anode 7-segment display. 2-digit 7-segment numeric display is connected to the upper & lower nibbles of Port 1 via a two BCD to 7-segment decoders. Port bits 3.0, 3.1, 3.3 & 3.4 0 are connected to 4 push buttons (S1 to S4) respectively.
8 Experiment 5 Laboratory
B1. Controlling a 7-segment numeric display A source program shown in table B1.1 controls the 7-segment display at Port 0 to show the digits 0-F in counting up manner. B1.1 Complete the lines 29 – 31 in table B1.1. B2.2 Use the 8051 simulation software to check the correct execution of the program. B2.3 Use the HT1000 89C51 writer to write the HEX file of the program into a blank 89C chip. B2.4 Insert the 89C51 chip to the ADC & 7-segment Display training board and observe the result of execution. Table B1. Line Label Mnemonics Operands Remarks 1 ORG 00h 2 MOV R3, #0 ;reset the counter 3 MOV DPTR, #TABLE 4 MOV P0, #01000000b ;display 0 5 ;subroutine to count from 0- 6 COUNT_UP: INC R3 ;increment the counter 7 CJNE R3, #16, CONT ;if R3≠10, continue counting 8 MOV R3, #0 ;otherwise count again from 0 9 CONT: MOV A, R 10 MOVC A, @A+DPTR ;display the value of R3 in 11 MOV P0, A ;7-segment format 12 ACALL DELAY 13 AJMP COUNT_UP 14 15 DELAY: MOV R5, #5 ;sets the delay time 16 LOOP1: MOV R6, # 17 LOOP2: MOV R7, # 18 LOOP3: DJNZ R7, LOOP3 ;inner loop 19 DJNZ R6, LOOP2 ;middle loop 20 DJNZ R5, LOOP1 ;outer loop 21 RET ;return to main program 22 23 ;lookup table to convert from hex to a corresponding digit 24 TABLE: DB 01000000b, 01111001b ;0, 1 25 DB 00100100b, 00110000b ;2 , 26 DB 00011001b, 00010010b ;4, 5 27 DB 00000010b, 01111000b ;6, 7 28 DB 00000000b, 00010000b ;8, 9 29 DB _________b,_________b ;A, b 30 DB _________b,_________b ;C, d 31 DB _________b,_________b ;E, F 32 END
10 Experiment 5 Laboratory
B2.1 By using the 8051 simulation software, correct the program as required. B2.2 Write the HEX file of the program into a blank 89C51 chip. B2.3 Check the program by the ADC & 7-segment Display training board. Table B3.
Line Label Mnemonics Operands Remarks 1 ORG 00h 2 MOV P1, #0 ;Display ‘00’ 3 MOV P2, #0FFh ;set port 2 as input port 4 MOV P3, #0FFh ;set port 3 output to High 5 ; 6 STARTCON: CLR P3.6 ;Set port bit 3.6 to Low, 7 NOP ;start ADC conversion 8 SETB P3.6 ;reset port bit 3.6 to High 9 NOP 10 CHK_END: JB P3.2, CHK_END ;check for end of conversion 11 NOP 12 READ: MOV A, P2 ;input from ADC 13 ; 14 MOV P1, A ;output to port 1 15 ACALL DELAY 16 AJMP STARTCON 17 18 19 20 21 22 ; 23 DELAY: MOV R5, #5 ;sets the delay time 24 LOOP1: MOV R6, # 25 LOOP2: MOV R7, # 26 LOOP3: DJNZ R7, LOOP3 ;inner loop 27 DJNZ R6, LOOP2 ;middle loop 28 DJNZ R5, LOOP1 ;outer loop 29 RET ;return to main program 30 END
Note: As the pins of (^) CS and RD are directly connected to the ground in the training board, they are always at LOW input. That means the ADC is always selected and ready for output. So the source program in the above table has not necessary to include any instructions for chip selection and read action of the ADC.
EEE3410 Microcontroller Applications
Laboratory Experiment 5 11
B2.4 After the program is corrected and executed by a 89C51 chip, complete the table below by first turning the potentiometer knob at the end of counter clockwise direction, record the voltage input to the ADC by a DMM and the value displayed by the 2-digit 7-segment display. Then slowly turn the knob in clockwise direction until at the end position. Record down the values displayed at any four intermediate positions. Compare with the voltage values measured by DMM.
Position of knob
Value indicated by the 2-digital 7-segment display
Analog voltage inputted to the ADC (Volts)
At Intermediate position 1
At Intermediate position 2
At Intermediate position 3
At Intermediate position 4
At Full clockwise