0% found this document useful (0 votes)
115 views17 pages

Interfacing 7 Segment Display with 8051

The document discusses interfacing a 7-segment display with the 8051 microcontroller, detailing various components and programming examples. It includes circuit diagrams, example programs for LED blinking and key press detection, as well as flowcharts for displaying numbers on the 7-segment display. The document aims to provide practical insights into using the 8051 for controlling displays and other peripherals.

Uploaded by

kmbalaji090507
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
115 views17 pages

Interfacing 7 Segment Display with 8051

The document discusses interfacing a 7-segment display with the 8051 microcontroller, detailing various components and programming examples. It includes circuit diagrams, example programs for LED blinking and key press detection, as well as flowcharts for displaying numbers on the 7-segment display. The document aims to provide practical insights into using the 8051 for controlling displays and other peripherals.

Uploaded by

kmbalaji090507
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

YCCE, Nagpur MGI

7 segment display with 8051

Dr. P. T. Karule
Professor
Department of Electronics Engineering
Yeshwantrao Chavan College of Engineering, Nagpur (M. S.)
Email: ptkarule@[Link]
Website: [Link]

8051 Microcontroller
Interfacing with 8051

• LED, Key
• 7 segment display
• Keyboard
• DAC
• ADC
• Stepper Motor
• LCD
• I2C Bus

30-Apr-20 ptkarule@[Link] 2
Minimum 8051 Circuit

(VCC) 40 +5V

10µF
8K2
9 (RST)
10K
(EA) 31

8051
33pF
18 (XTAL2)

12MHz

19 (XTAL1)
33pF
20 (GND)

30-Apr-20 ptkarule@[Link] 3
LED & Switch

30-Apr-20 ptkarule@[Link] 4
Example #1
 LED interface
LED

P2.0
P2.1
P2.2
P2.3
P2.4 1
0
P2.5
P2.6
P2.7

GND
SETB P2.5 ; LED ON
8051
CLR P2.5 ; LED OFF

30-Apr-20 ptkarule@[Link] 5
Q. Write program to blink LED
Main Program
Sub Program

Turn LED ON Delay Program


N = N-1
Till N =0
Wait for 1 sec

Turn LED OFF

Wait for 1 sec

30-Apr-20 ptkarule@[Link] 6
Q. Write program to blink LED
Program:
$MOD51
ORG 0000H
SJMP START
ORG 0040H
START: SETB P2.5 ; LED ON
ACALL delay_1sec ; 1 sec delay
CLR P2.5 ; LED OFF
ACALL delay_1sec ; 1 sec delay
SJMP START
; Subroutine for delay
delay_1sec: MOV R2,#04H
L4: MOV R3,#0FFH
L3: MOV R4,#0FFH
L2: DJNZ R4,L2
DJNZ R3,L3
DJNZ R2,L4
RET
END

30-Apr-20 ptkarule@[Link] 7
Example #2
 Switch interface

VCC

P2.0
P2.1
P2.2 Key
P2.3
P2.4
P2.5
P2.6
P2.7

GND
8051

30-Apr-20 ptkarule@[Link] 8
Q. Write Program to check Key Press?
 Push Button interface
JNB P2.4, L1

VCC

P2.0 Key Read P2.4


P2.1
P2.2
P2.3 P2.4 =0 Yes
P2.4
P2.5 ? L1
P2.6 No
P2.7 1
GND Key Pressed
8051

30-Apr-20 ptkarule@[Link] 9
7 Segment Display

30-Apr-20 ptkarule@[Link] 10
Example #1
 Common Anode Seven Segment Display is connected with P2 of
8051 and write program to display 0 to F at an interval of 1 sec.
Digit 7 segment Code Hex code
dp g f e d c b a
a
P2.0 0 1 1 0 0 0 0 0 0 C0H
b
P2.1 1 1 1 1 1 1 0 0 1 F9H
c
P2.2 2 1 0 1 0 0 1 0 0 A4H
d
P2.3 3 1 0 1 1 0 0 0 0 B0H
e 4 1 0 0 1 1 0 0 1 99H
P2.4
f 5 1 0 0 1 0 0 1 0 92H
P2.5 6 1 0 0 0 0 0 1 0 82H
P2.6 g
7 1 1 1 1 1 0 0 0 F8H
P2.7 dp
8 1 0 0 0 0 0 0 0 80H
9 1 0 0 1 0 0 0 0 90H
A 1 0 0 0 1 0 0 0 88H
b 1 0 0 0 0 0 1 1 83H
C 1 1 0 0 0 1 1 0 C6H
8051 d 1 0 1 0 00 0 1 A1H
5V
E 1 0 0 0 0 1 1 0 86H
F 1 0 0 0 1 1 1 0 8EH

30-Apr-20 ptkarule@[Link] 11
Example #1 (cont..)
Flowchart Program
START

$MOD51
INITIALISE DPTR =0200H MOV DPTR,#0200H
MOV R1, #00H
INITIALISE COUNTER R1=00H L1: MOV A, R1
ANL A, 0FH
MOVC A, @A+DPTR
MASK 4 MSB OF R1 = 0X
MOV P2, A
ACALL delay
GET 7 SEGMENT CODE FROM LOOK UP INC R1
TABLE AND SEND IT TO DISPLAY VIA PORT 2
SJMP L1

CALL DELAY OF 1 SEC


ORG 0200H
DB 0C0H, 0F9H, 0A4H, 0B0H
INCREMENT COUNTER R1
DB 99H, 92H, 82H, 0F8H, 80H
DB 90H, 88H, 83H, 0C6H
DB 0A1H, 86H, 8EH
JUMP TO DISPLAY END

30-Apr-20 ptkarule@[Link] 12
Example #2
 Common Anode Seven Segment Display is connected with P0 (4
LSB) through IC 7447 and write program to display 0 to 9 at an
interval of 1 sec.

a
P0.0 A
b
P0.1 B
c
P0.2 C
d
P0.3 D
e
7447
f
g
dp

BCD to 7 segment
8051 code converter

5V

30-Apr-20 ptkarule@[Link] 13
Example #1 (cont..)
Flowchart START Program

INITIALISE COUNTER $MOD51


R1=00H ORG 0000H
MOV SP,#40H
Transfer R1 to Acc L5: MOV R1,#00H
L1: MOV A,R1
MOV P0,A ; send it to display
Send 4 bit BCD to Port 0 (LSB)
ACALL delay_1sec
INC R1
Wait for 1 second CJNE R1,#0AH,L1 ;(A) > 9
SJMP L5
; Subroutine for delay
INCREMENT COUNTER R1 delay_2sec: MOV R2,#08H
L4: MOV R3,#0FFH
L3: MOV R4,#0FFH
Compare counter > 9 L2: DJNZ R4,L2
DJNZ R3,L3
A <=9 DJNZ R2,L4
A >9 RET
END

30-Apr-20 ptkarule@[Link] 14
Interfacing 7 segment display

P2.0
a a a a
P2.1
b b b b
P2.2
c c c c
P2.3
d d d d
P2.4
e e e e
P2.5
f f f f
P2.6
g g g g
P2.7
dp dp dp dp

8051
P1.0

P1.1

P1.2

P1.3

30-Apr-20 ptkarule@[Link] 15
Interfacing 7 segment display

0
1
P2.0 1a a a a
P2.1
0b
1 b b b
P2.2
0c
1 c c c
P2.3
1d
0 d d d
P2.4
P2.5 1e
0 e e e

P2.6 0f
1 f f f

P2.7 0g g g g
dp dp dp dp

8051
1
0
P1.0

P1.1 1
0

P1.2 1
0

0
1
P1.3

30-Apr-20 ptkarule@[Link] 16
Interfacing two digit 7 segment display

P0.0
a a
P0.1
b b
P0.2
c c
P0.3 LATCH d d
P0.4 (74573) e e
P0.5
f f
P0.6
g g
P0.7 CLK dp dp

8051
P1.2

P1.1

P1.0

30-Apr-20 ptkarule@[Link] 17

You might also like