8051 I/O Interfacing. Need for more ports PPI 8255 8255 – 8051 Interfacing Key board Interfacing LED Interfacing 7 Segment LED Interfacing. I/O Interfacing. I/O Devices connected through ports 8051 has 4 I/O ports P0 to P3. In case 8051 needs external program and/or data memory
I/O Devices connected through ports
8051 has 4 I/O ports P0 to P3.
In case 8051 needs external program and/or data memory
P0 and P2 are used for address bus & P0 is used for data bus.
Only 2 ports (P1,P3) remain i.e. only 2 I/O devices can be connected.
In case system application needs interrupt, serial I/O, i.e. alternate functions of P3
Only 1 port (P1) remain i.e only 1 I/O device can be interfaced.
Only one port (P1) in available.
- different from 8051 ports.
(PA7 – PA0) (PC7 – PC4)
(PB7 – PB0) (PC3 – PC0)
The 8255A block diagram.
an input ports on Reset.
-A1. A0 are lower 2 bits of as address lines.
Issued by µp
Mode 0-Basic Input –Output
Mode 1-Strobed Input-Output
Mode 2-Strobed Bidirectional Bus
- Any port A , B, C(U) or C(L) can be input or output
- Provides means for transferring I/O data to or from a specified port in conjunction with strobes or hand shaking signals.
- Port C lines are used for hand shaking signals.
- Port A and Port B can be used as input or output.
- Port A uses port C (Upper) lines for hand shaking – Group A
- Port B uses port C (Lower) lines for hand shaking – Group B
- We have already mentioned that 8255 ports can be configured using control register (A1 A0 = 11).
- The control word format for configuration of 8255 is shown
We need to configure 8255 with Port A as input, Port B as output, Port C (L) as output, port C (upper) as input using mode=00
8255 – 8051 Interfacing
I/O and memory are treated separately
Example – 8086 has IN and OUT as I/O read and write instructions. It has same RD (for read),WR (for write), signal for I/O and memory read- write. It has M/IO to identify memory or I/O read-write.
In Memory mapped I/O
A1 – A0 =00-Port A is selected
=01-Port B is selected
=10-Port C is selected
=11-Control register is selected
Port A address =FE10H
Port B address =FE11H
Port C address =FE12H
Control register address = FE13H
MOV DPTR, # FEI3H
MOV A, # 98H
MOVX, @DPTR, A
(will configure 8255)
MOV DPTR, # FE10H
MOVX A, @ DPTR
(will bring the content of Port A to ACC.)
Assume address = FE10
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
F E 1 0
CS of 8255
Many Variations of circuits are possible
0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0
Problem - 1
1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0
Decoding of 8255 Address E000H to generate chip select
Reading and writing to 8255 ports
Port A - E000H
Port B - E001H
Port C - E002H
Control register - E003H
Port A - Output
Port B - Input
Port C - Output
Mode = 0
What will be control word of 8255 ?
We may configure 8255 by writing 82H to control register in two ways:-
MOV A,# 82H
Note - E003 is location in external data memory.
Other way of writing (A) will be
- Use shift/rotate RRL , RRL etc
OUT (High when the key is pressed)
Basic keyboard operation is shown in figure
Basic keyboard operation-single key.
Basic keyboard operation- two keys.
Basic keyboard operation – four keys.
2x2 keyboard operation
8x8 keyboard interfacing with microprocessor
row no. and column no.
i.e. position of key is identified
key code is taken from table and used in the program.
Code table for 8 x 8 keyboard
Keyboard- microprocessor interface software flowchart
Enable the Ith row
Set the address of the code for the first key on this row
Check for key depression
Determine the column number and the code of the key
- 16 keys (0 to F) arranged in
- 4 x 4 key board
emits light energy when conducts
Anode is held at higher voltage than cathod
[ Port bit = 1
i.e glows ]
LED interface with microprocessor
All cathodes connected together
Microprocessor interface to LED (common cathode)
[ Port bit = 0
i.e glows ]
together to 5V
Cathodes of LED’s connected to port lines
Microprocessor interface to LED (common anode).
Seven segment LED’s – The LED’s can be arranged in the fashion shownin
Example :- For displaying A, all segments except d and h should glow.
Note – Previously there were only seven segments. Eighth segment h has been added later. But name seven segment has remained stock.
Common Catnode - Anodes connected to bits catnodes connected to ground.
Common Anode – Anodes connected to +5V catnodes connected to bit.
76 5 4 3 2 1 0
ab c d e f g h
76 5 4 3 2 1 0
hg f e d c b a
0-Glow the segment for common Anode configuration
1-Do not glow
Common Catnode - bit =1, segment glows
bit = 0 – doesn’t glow
Common Anode -bit = 0 – segment glows
bit = 1 – segment doesn't glow
Microprocessor interface to seven-segment LED (parallel interface).
in common Anode fashion
MOV Px, #00H – will glow all the segments
CLR Px .3 – will glow segment No. 3 i.e segment ‘e’.
Serial Interface- Overcomes the limitation of parallel interface in case of large no. of 7 segment displays.
Microprocessor interface to seven-segment LED(serial interface)
Load LSB from
Load next bit
Example:- Display code for A
7 6 5 4 3 2 1 0
h g f e d c b a
for common anode configuration .