Microprocessor | 8255 (programmable
peripheral interface)
8255 is a popularly used parallel, programmable input-output device. It can be used to transfer
data under various condition from simple input-output to interrupt input-output. This is
economical, functional, flexible but is a little complex and general purpose i/o device that can be
used with almost any microprocessor.
8255 pin diagram –
It has 24 pins that can be grouped in two 8-bit parallel ports: A and B called Port A(PA) and
Port B(PB) with the remaining eight known as Port C(PC). Port C can be further divided into
groups of 4-bits ports named Cupper(Cu) and Clower(Cl). There are 40 pins and operates in +5
regulated power supply.
Modes of 8255 – It works in two modes:
1. Bit set reset (BSR) mode
2. Input/output (I/O) mode
To know in which mode the interface is working we need to know the value of Control word.
Control word is a part of control register in 8255 which specify an I/O function for each port.
This is format of control word 8255.
If the most significant bit of control word or D7 is 1 then 8255 works in I/O mode else, if it’s value is
0 it works in BSR mode.
1. BSR Mode – When MSB of the control register is zero(0), 8255 works in Bit Set-Reset
mode.in this only PC bit are used for set and reset.
2. I/O Mode – When MSB of the control register is one(1), 8255 works in Input-Output
mode.it is further divided into three categories.
3. Mode 0 – In this mode all three ports (PA, PB, PC) can work as simple input function or
output function also in this mode there is no interrupt handling capabilities.
4. Mode 1 – In this either port A or port B can work and port C bits are used as Handshake
signal before actual data transmission plus it has interrupt handling capabilities.
5. Mode 2 – In this only port A works and port B can work either in Mode 0 or Mode 1 and
the 6 bits of port C are used as Handshake signal plus it also has to interrupt handling
capability.
To communicate with peripherals through 8255 three steps are necessary:
1. Determine the addresses of Port A, B, C and Control register according to Chip Select Logic
and the Address lines A0 and A1.
2. Write a control word in control register.
3. Write I/O instructions to communicate with peripherals through port A, B, C.
The common applications of 8255 are:
• Traffic light control
• Generating square wave
• Interfacing with DC motors and stepper motors
Interface 8255 with 8085 microprocessor for
addition
Problem – Interface 8255 with 8085
microprocessor and write an assembly
program that determines the
addition of contents of port A and port
B and stores the result in port C.
Example –
Algorithm –
1. Construct the control word register
2.Input the data from port A
and port B
3.Add the contents of port A
and port B
4.Display the result in port
C
Program –
Mnemonics Comments
MVI A, 92H A ← 92
OUT 83H Control Register ← A
IN 80H A ← Port A;
MOV B, A B ← A;
IN 81H A ← Port B;
ADD B A ← A+B;
OUT 82H Port C ← A
RET Return
Explanation –
• MVI A, 92H means that the value of the control register is 92.
D7=1 as it is in I/O mode.
D6=0 & D5=0 as Poet A is in m0 mode.
D4=1 as Port A is taking input.
D3=0 & D0=0 as Port C is not taking part.
D2=0 as mode of Port B is m0.
D1=1as Port B is taking the input.
• OUT 83H putting the value of A in 83H which is the port number of the port control
register.
• IN 80H taking input from 80H which is the port number of port A.
• MOV B, A copies the content of A register to B register.
• IN 81H takes input from 81H which is the port number of port B.
• ADD B add the contents of A register and B register.
• OUT 82H displays the result in 81H which is the port number of port C.
• RET return
Interface 8255 with 8085 microprocessor for 1’s
and 2’s complement of a number
Problem – Interface 8255 with 8085 microprocessor and write an assembly language program to
display 99 in Port A, 1’s complement of 99 in Port B, and 2’s complement of 99 in Port C. If Port
addresses are 30H, 32H, and 33H resp.
Example –
D D D D D D D D
7 6 5 4 3 2 1 0
1 0 0 0 0 0 0 0
Algorithm –
1. Construct the control word register.
2. Input value of accumulator A.
3. Display value of A in Port A.
4. Now 1’s complement of A is calculated and result is displayed in Port B.
5. Now 2’s complement of A is calculated by adding 1 to 1’s complement of A. The result is
displayed in Port C.
Program –
Mnemonics Comments
MVI A, 80 A<–80
OUT 33 Control Register<–A
MVI A, 99 A<–99
OUT 30 Port A<–A
CMA 1’s complement of A
OUT 31 Port B<–A
INR A A<–A+1
OUT 32 Port C<–A
RET Return
Explanation –
1. .MVI A, 80: Value of control register is 80.
2. OUT 33: Putting the value of A in 33H which is port number of port control register.
3. .MVI A, 99: Value of A is equals to 99.
4. OUT 30: Displaying the value of A in 30H which is port number of Port A.
5. CMA: Calculates 1’s complement of A.
6. OUT 31: Displaying 1’s complement of A in 31H which is port number of Port B.
7. INR A: 1’s complement of A is incremented by 1 i.e. 2’s complement of A is calculated.
8. OUT 32: Displaying 2’s complement of A in 32 H which is port number of Port C.
9. RET: Return.
Subtract content of two ports by interfacing
8255 with 8085 microprocessor
Problem – Write an assembly program which determine the subtraction of contents of port B from
port A and store the result in port C by interfacing 8255 with 8085 microprocessor.
Example –
Algorithm –
1. Construct the control word register
2. Input the data from port A and port B
3. Subtract the contents of port A and port B
4. Display the result in port C
5. Halt the program
Program –
MNEMONICS COMMENTS
MVI A, 92 A <- 92
OUT 83 Control Register <- A
IN 81 A <- Port B
MOV B, A B <- A
IN 80 A <- Port A
SUB B A <- A – B
OUT 82 Port C <- A
RET Return
Explanation –
1. MVI A, 92: means that the value of control register is 92.
D7=1 I/O mode
D6=0 & D5=0 Port A is in mode 0
D4=1 Port A is taking input
D3=0 & D0=0 Port C is not taking part
D2=0 Port B is in mode 0
D1=1 Port B is taking input
2. OUT 83: putting the value of A in 83H which is the port number of port control register.
3. IN 81: take input from 81H which is the port number of port B.
4. MOV B, A: copies the content of A register to B register.
5. IN 80: taking input from 80H which is the port number of port A.
6. SUB B: subtract the contents of A register and B register.
7. OUT 82: display the result in 81H which is the port number of port C.
8. RET: return