Air University: Department of Electrical and Computer Engineering

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

AIR UNIVERSITY

DEPARTMENT OF ELECTRICAL AND COMPUTER


ENGINEERING

EXPERIMENT NO3

Lab Title Interfacing Seven Segment Display with 8051 Microcontroller


Student Name: Hira Nawaz Reg. No: 190519
Objective:to get familiar with lookup tables , To display data on seven segments

LAB ASSESSMENT:

Attributes Excellent Good Average Satisfactory Unsatisfactory


(5) (4) (3) (2) (1)
Ability to Conduct
Experiment
Ability to assimilate the
results
Effective use of lab
equipment and follows the
lab safety rules

Total Marks: Obtained Marks:


LAB REPORT ASSESSMENT:
Attributes Excellent Good Average Satisfactory Unsatisfactory
(5) (4) (3) (2) (1)

Data presentation

Experimental results

Conclusion

Total Marks: Obtained Marks:

Date: Signature:
EXPERIMENT 03

Interfacing Seven Segment Display with 8051 Microcontroller

Objective:

 Familiarizing students with the usage of lookup table


 Displaying data sent on the output port on seven segment display

Equipment:

 Hardware:
1. 8051 microcontroller
2. Seven segment displays (SSDs)
3. Resistances
 Software:
1. Keil µVision
2. SmartPRO 5000U

Introduction:

Addressing Modes of 8051:

1. Immediate Addressing Mode:

In this addressing mode the source operand is a constant. In immediate addressing mode, when the
instruction is assembled, the operand comes immediately after the opcode. Notice that the data in
this instruction must be preceded by pound sign. For example:

mov A,#25h

2. Register Addressing Mode:


Register addressing mode involves registers to hold the operands or data to be manipulated. For
example:
mov aAR0
mov R2,A
The movement of data between registers (R0-R7) is invalid.

3. Direct Addressing Mode:


In the direct addressing mode, the data is in a ram memory location whose address is known, and
this address is given as a part of instruction. Contrast this with the immediate addressing mode in
which the operand is provided itself with the instruction. The “#” sign distinguishes between the
two modes. For example:
mov R0,40h
mov R4,7Fh
4. Register Indirect Addressing Mode:
In the register indirect addressing mode, a register is used as a pointer to the data. Only R0 and R1
are used as pointer. When R0 and R1 are used as a pointer, that is when they hold the address of
RAM location, they must be preceded by “@” sign as shown below:
mov A,@R0 ; move contents of RAM location whose address is held by R0 into A

5. Indexed Addressing Mode:


Indexed addressing mode is widely used in accessing the data elements of the look-up table entries
located in the program ROM space of 8051. The instruction used for this purpose is “movc
A,@A+DPTR”. The 16-bit DPTR and a register are used to form the address of entry in lookup
table. In the instruction movc c means code so this instruction means move code. In this instruction
the contents of a are added to the 16-bit DPTR form the 16bit address of required data.

Lookup Table:A lookup table is an array that replaces runtime computation with a simpler array
indexing operation. The savings in processing time can be significant, because retrieving a value from
memory is often faster than carrying out an "expensive" computation or input/output operation. The look-
up table allows access to elements of a frequently used table with minimum operations. We design a
lookup table of our desired values which can be accessed by data pointer. It is a very useful method in
various implementations of several applications i.e., you can save many quantization points to represent a
sin wave and you can send them one by one to any port and interfacing a digital to analog converter with
that port will change these levels to their analog equivalent levels producing a sin wave.

Seven Segment Displays:The seven segment display IC is LT-541 or LSD5061-11. Each of the
segments of the display is connected to a pin on the 8051. In order to light up a segment on the pin must
be set to 0V. To turn a segment off the corresponding pin must be set to 5V. This is simply done by
setting the pins on the 8051 to ‘1’ or ‘0’. SSDs are

1. Power-hungry (10ma per LED)

2. Pin-hungry (8 pins per 7-seg display)

However, they are cheaper than LCD display. 7-SEG Display is available in two types:
1. Common anode
2. Common cathode

Common anode displays are most suitable for interfacing with 8051 since 8051 port pins can sink current
better than sourcing it.

In common anode the common terminal is tied to +5V through a resistance and 0V should be provided to
the segment you need to glow or turn on.
The following pin assignment and bit sequence is used for common anode SSD interfacing with 8051.

Cathode pins should be connected through resisters to limit current. Anode is tied to 5V
source.Procedure:

 Use port 2 to implement a single digit counter and connect it from LSB to MSB in a sequence
starting from segment a tosegment h.

 The segment h means dot should be permanently off.

 While implementing a two digit counter use port 3 for 2nd digit and make sure you connect the port
in the same way as you connected for first digit.

 The sequences used should be according to connections made.

 It is better to use resistances with Seven Segment Displays to limit the current to avoid overheating.

Example:

The following code displays a ‘1’ on SSD.

org 000h
mov A,#11111001b
mov P2,A
call delay
call delay
delay: mov r0,#04
here: mov r1,#255
again1: mov r2,#255
again2: djnz r2,again2
djnz r1,again1
djnz r0,here
ret
end
Lab Task 1:
Write an assembly language code to display numbers from 0-9 using a common anode SSD. Use a time
delay of 0.5 seconds between each transition. Burn this code on 8051 microcontroller chip and interface
with SSD to obtain the results. Verify the results in Proteus.

EXPLANATION:
 We will make a look up table of common anode seven segment display at first
 We will access the location of lookup table through dptr.
 We will use movc command to move dptr in accumaltor using port 2
 The time delay will e of 0.5 sec
 After creating dealy function we will end the coe , burn it.
 Generate a hex file of code.
 Verify results in proteus

CODE:
org 50h
db 11000000b, 11111001b, 10100100b,10110000b, 10011001b, 10010010b, 10000010b,
11111000b, 10000000b, 10010000b
org 00h
now: mov dptr,#50h
mov r1,#10
next: clr A
movc A, @A+dptr
mov p2,A
call delay
inc dptr
djnz r1,next
sjmp now
delay: mov r5, #04
here: mov r6,#255
again: mov r7,#255
againn: djnz r7, againn
djnz r6, again
djnz r5,here
ret
end
PROTEUS SUIMULATION:
Lab Task 2:
Write an assembly language code to display numbers from 9-0 using a common cathode SSD. Use a time
delay of 0.5 seconds between each transition. Generate the hex file for this code and verify the results in
Proteus.

EXPLANATION
 We will make a look up table of common cathode seven segment display at first
 We will access the location of lookup table through dptr.
 We will use movc command to move dptr in accumaltor using port 2
 The time delay will e of 0.5 sec
 After creating dealy function we will end the coe , burn it.
 Generate a hex file of code.
 Burn hex file in proteus and verify results

CODE:
ORG 50h
db 01101111b , 01111111b, 00000111b, 01111101b, 01101101b,01100110b,
01001111b,01011011b,00000110b, 00111111b

ORG 0000h
main:mov dptr,#50h
mov r1,#10
repeat:clr A
movc A,@A+dptr
mov P2,A
call delay
call delay
inc dptr
djnz r1,repeat
sjmp main

delay: mov r5,#04


here: mov r6,#255
again:mov r7,#255
againn:djnz r7,againn
djnz r6,again
djnz r5,here
ret
end
PROTEUS SIMULATION
Lab Task 3:
Use direct addressing mode to write an assembly language program to display numbers from 0-9 using a
common cathode SSD. Use a time delay of 0.5 seconds between each transition. Generate the hex file for
this code and verify the results in Proteus.

EXPLANATION:
 We will make a look up table of common cathode seven segment display at first
 We will access the location of lookup table through dptr.
 We will use movc command to move dptr in accumaltor using port 2
 The time delay will e of 0.5 sec
 After creating dealy function we will end the coe , burn it.
 Generate a hex file of code.
 Burn hex file in proteus and verify results
CODE:
org 500h
db 00111111b, 00000110b, 01011011b, 01001111b, 01100110b, 01101101b, 01111101b, 00000111b,
01111111b, 01101111b
org 00h
now: mov dptr,#500h
mov r1,#10
next: clr A
movc A, @A+dptr
mov p2,A
call delay
inc dptr
djnz r1,next
sjmp now
delay: mov r5, #04
here: mov r6,#255
again: mov r7,#255
againn: djnz r7, againn
djnz r6, again
djnz r5,here
re
end
PROTEUS SIMULATION:
Conclusion:

In this lab we learned about the use of lookup table. We were able to display data sent on the output
port on seven segment display.We also got familiar with the addressing modes. We were able to
do our coding as specified by the instructor in particular addressing mode. We are now able to
code in assembly language effectively.

You might also like