+ All Categories
Home > Documents > Seven Seg Display

Seven Seg Display

Date post: 28-Oct-2014
Category:
Upload: vikas-ravi
View: 45 times
Download: 3 times
Share this document with a friend
Popular Tags:
12
EEE3410 Microcontroller Applications Laboratory Experiment 5 1 © Vocational Training Council, Hong Kong LABORATORY – Experiment 57-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/2006
Transcript
Page 1: Seven Seg Display

EEE3410 Microcontroller Applications

Laboratory Experiment 5 1

© Vocational Training Council, Hong Kong

LABORATORY – Experiment 5

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/2006

Page 2: Seven Seg Display

2 Experiment 5 Laboratory

© Vocational Training Council, Hong Kong

Part A: Background Information

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

a b c d e f g Dp Common

Common-cathode configuration

a b c d e f g Dp Common

Common-anode configuration

Page 3: Seven Seg Display

EEE3410 Microcontroller Applications

Laboratory Experiment 5 3

© Vocational Training Council, Hong Kong

A2. Analog-to-digital conversion (A/D)

Most real time data (e.g. temperature, voltage, velocity) are analog signal, i.e. the signal is

continuous varying with time. Microcontroller is a digital device. It can only read and

manipulate data in digital form. If this kind of real time analog data is being controlled by

microcontroller, some means must be used first to convert the analog data to digital data before

manipulating by microcontroller. The common process to get these analog data is to use a

device called a transducer (also called sensor) to measure their values. The transducer normally

converts measured value into electrical signal (which is either voltage or current) for further

conversion to digital form. An example of transducer is a thermistor. Since its resistance varies

with the ambient temperature, so the current passing through it will also vary. As a result, current

value depends on the temperature being measured. Measure the current will then be the same

as to measure the temperature. Yet, the output from a transducer (voltage/current) is still analog;

a device is needed to convert them in digital signals (“digitization”). Such a device is called an

analog-to-digital converter (ADC), and this process is called analog-to-digital (A/D) conversion.

Once the signal is digitized, it can be sent to the microcontroller for further processing.

A2.1 The ADC0804 IC

The ADC0804 IC is one of the most popular analog-to-digital converters. It is in the family

of the ADC0800 series. It works with a power supply of +5V, and has a resolution (i.e.

output) of 8 bits.

Pin description of the ADC0804:

Chip select (CS)

Pin CS is used to activate the ADC0804 IC. The IC is

activated and ready to use if a LOW signal is set to this

pin.

Read (RD ) (Data output enable)

Pin RD is also called “output enable”. It is an

active-low output signal. It is used to get the converted

data out of the ADC0804 IC. With CS=0, if a

high-to-low pulse is applied to RD , the 8-bit digital is

then output to the data pins D0-D7 for pick-up. Pin diagram ADC0804

D0 D1 D2 D3 D4 D5

D6

D7

V I+

VREF/2

V I-

CLK

INTR

WR

RD

CS

CLKR

AGND

VCC

DGND

20 19 18 17 16 15

14

13 12

11

1 2 3 4 5 6

7

8 9

10

Page 4: Seven Seg Display

4 Experiment 5 Laboratory

© Vocational Training Council, Hong Kong

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/2

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-D7

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=0

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 (V IN) is in the

range 0-5V. Because the ADC0804 IC has a resolution of 8 bits, the range is divided

into 28=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:

255

V

122

V2

sizestep REF8

REF

=−

×=

The digital data value (DOUT) of the ADC804 IC is:

sizestep

VD IN

OUT =

Page 5: Seven Seg Display

EEE3410 Microcontroller Applications

Laboratory Experiment 5 5

© Vocational Training Council, Hong Kong

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: V0196.0V255

5sizestep == ;

179or1780196.0

5.3DOUT == (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 ADC0804

DB0 DB1

DB2 DB3

DB4 DB5

DB6

DB7

VI+

VREF

VI-

CLK

INTR

WR

RD

CS

CLKR

AGND

ADC0804

VCC

8051 Microcontroller

Input bits

Output Control bits

Input analog voltage

Fig. A2.1 Interface of ADC0804 to 8051 microcontroller

Page 6: Seven Seg Display

6 Experiment 5 Laboratory

© Vocational Training Council, Hong Kong

(Fig. A2.3 The “read and write signal” timing diagram for ADC804)

Sequence of signal to control the ADC0804

1. Set CS to LOW. (Select the ADC IC)

2. Send a low-to-high pulse to WR , so as to start data conversion. Return CS to High again to de-select the ADC

3. Keep monitoring INTR . If INTR is LOW, that means the conversion is finished.

If INTR is still HIGH, keep polling until it becomes LOW.

4. Set CS to LOW to select the ADC

5. Send a high-to-low pulse to RD so that data read by 8051 input port can be done

6. Return RD to High again to indicate port reading completed

7. Return CS to High again to de-select the ADC 8. Repeat steps for another conversion

Read it

End conversion Start conversion

Data out

CS

WR

D0 – D7

INTR

Note: CS is set to low for both RD and WR pulses

Page 7: Seven Seg Display

EEE3410 Microcontroller Applications

Laboratory Experiment 5 7

© Vocational Training Council, Hong Kong

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.

Page 8: Seven Seg Display

8 Experiment 5 Laboratory

© Vocational Training Council, Hong Kong

Part B: Procedures

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 89C51

chip. B2.4 Insert the 89C51 chip to the ADC & 7-segment Display training board and observe the

result of execution.

Table B1.1 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-9

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, R3

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, #250

17 LOOP2: MOV R7, #200

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 ,3

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

Page 9: Seven Seg Display

EEE3410 Microcontroller Applications

Laboratory Experiment 5 9

© Vocational Training Council, Hong Kong

B2. Controlling 7-segment numeric displays through BCD decoder/driver

A source program shown in table B2.1 is expected to control the 2-digit 7-segment display at

Port 1 to show the values from 00 to 99 in counting up manner. But it cannot correctly

display the values ONE after ONE in sequence. You are required to correct the program in

table B2.1 to give the right result.

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 B2.1 Line Label Mnemonics Operands Remarks

1 ORG 00h

2 MOV A, #0 ;reset the counter

3

4 COUNT_UP: MOV P1, A ;display the value of A

5 ACALL DELAY

6 INC A ; A = A + 1

7 CJNE A, #100, CONT ;if A≠100, continue counting

8 MOV A, #0 ;otherwise count again from 0

9 CONT: AJMP COUNT_UP

10 ;

11 DELAY: MOV R5, #5 ;sets the delay time

12 LOOP1: MOV R6, #250

13 LOOP2: MOV R7, #200

14 LOOP3: DJNZ R7, LOOP3 ;inner loop

15 DJNZ R6, LOOP2 ;middle loop

16 DJNZ R5, LOOP1 ;outer loop

17 RET ;return to main program

18 END

19

20

21

B3. Controlling ADC

A source program is given in table B3.1 which controls an 8-bit ADC0804 IC repetitively to

acquire analog voltage signals from a potentiometer, and convert the signals to 8-bit digital

values and finally to output the values to the Port 2 of 8051. After the 8-bit digital value is

inputted, the 8051 has to convert the 8-bit value to an equivalent decimal value and display

it by the 2-digital 7-segment display. When you turn the potentiometer, the analog voltage

input to the ADC will change and similarly, the digital values displayed will also change.

Problem: it is found that the analog voltage input, measure by a DMM, to the ADC cannot

be correctly displayed by the 2-digital 7-segment display.

Page 10: Seven Seg Display

10 Experiment 5 Laboratory

© Vocational Training Council, Hong Kong

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.1

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, #250

25 LOOP2: MOV R7, #200

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.

Page 11: Seven Seg Display

EEE3410 Microcontroller Applications

Laboratory Experiment 5 11

© Vocational Training Council, Hong Kong

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 Full counter clockwise “0 0” 0 V

At Intermediate position 1

At Intermediate position 2

At Intermediate position 3

At Intermediate position 4

At Full clockwise

Page 12: Seven Seg Display

12 Experiment 5 Laboratory

© Vocational Training Council, Hong Kong

Part C: Exercise

C1. Assume that pin Vref/2 is connected to a reference voltage of 2V. Determine the following.

(a) Step Size:

(b) Maximum range for Vin

(c) D7 – D0 value if Vin = 1.2 V

(d) Vin if D7 – D0 = 1111 1111

(e) Vin if D7 – D0 = 1101 1011

C2. What is the value for Vref/2 to set the ADC0804 has a step size of 8 mV.

- End -


Recommended