Unit 3 - Microprocessor & Its Application - WWW - Rgpvnotes.in
Unit 3 - Microprocessor & Its Application - WWW - Rgpvnotes.in
Peripheral Devices And Their Interfacing: The general purpose computer system consists of the CPU,
memory, keyboard, display unit and some special purpose input / output (I/O) devices. The central processing
unit (CPU) is referred as the microprocessor. This microprocessor is connected with I/O devices and are called
as peripheral devices. The microprocessor is heart of the computing system while all the peripheral devices
are built around the microprocessor. Since the processor can not work without memory, the memory
(primary) is also considered as an integral part of a microprocessor system.
The peripheral devices are connected with CPU to enable it to communicate with the user, so that the
microprocessor works efficiently and effectively. The special purpose peripheral devices such as
programmable interrupt controller (PIC), direct memory access (DMA), etc. simplifies both the hardware and
software considerably. The peripheral devices need initialisation control signal to communicate with CPU &
user. The memory does not need any special kind of initialisation signal. The peripheral device may be treated
as memory location by the CPU. The configuration methods of peripheral devices with CPU are discussed in
details.
PIO 8255 (Programmable Input Output Port): The IC 8255 is programmable peripheral input output port
through which the peripheral devices can be connected to communicate with 8-bit or 16-bit Intel
microprocessor. It has 24 input/output lines. These lines are individually programmed in two groups of 12-
lines each named as group-A and group-B. Each of these groups consists of subgroups of 8-bit port and a 4-bit
port. The group-A consist of 8-bit port-A (PA7-PA0) and 4-bit upper bits of port-C (PC7-PC4). The group-B
consist of 8-bit port-B (PB7-PB0) and 4-bit lower bits of port-C (PC 3-PC0). All the three ports can be used as
individually either as input or as output ports. These ports can be programmed using its internal register
called control word register (CWR). The internal architecture of IC 8255 is as shown in Fig.3.1 below.
Group
Group
A PA7-PA0
A Port
RD Group B
WR PC3-PC0
Read / Write Control Logic Port C
A0
A1
RESET Group B Group B
PB7-PB0
Control Port B
CS
Page no: 1
Pin Configuration of 8255 IC:
The pin configuration of 8255A is as shown in Fig.3.2
It is 40 pin IC and the pin details are as described
PA3 1 40 PA4 below. The 3 ports can be configured as buffered
PA2 2 39 PA5 input or latched output based on control word and
PA1 3 38 PA6 mode of operation
PA0 4 37 PA7 (i) PA7 – PA0 : Port A has 8 lines which can be
RD 5 configured as either output or input depending on
36 WR
CS 6
the control word register value.
35 RESET
GND 7 (ii) PB7 – PB0 : Port B has 8 lines which can be
8 34 D0
configured as either output or input depending on
A1 8 33 D1 the control word register value.
2
A0 9 5 32 D2 (iii) PC7 – PC4 : Port C has 8 lines which can be
PC7 10 5 31 D3 configured as either output or input depending on
PC6 11 the control word register value. Port C can also be
30 D4
PC5 A
12 29 D5 used as handshake signal lines in mode 1 and
PC4 13 28 D6 mode 2. Upper nibble of Port C are used as
PC0 14 handshake signal with Port A .
27 D7
PC1 15
(iv) PC3 – PC0 : In mode 1 & 2, the lower nibble of Port
26 Vcc
PC2
C lines are used as handshake lines with Port B.
16 25 PB7
(v) RD : It is active low input signal driven by the
PC3 17 24 PB6 microprocessor to indicate the read operation to
PB0 18 23 PB5 8255.
PB1 19 (vi) WR : It is active low input signal driven by the
22 PB4
PB2 20
21 PB3
microprocessor to indicate the write operation.
(vii) CS : It is a chip select line which enables the 8255
Fig.3.2 : Pin Configuration of 8255A to respond to read & write operation.
(viii) A1 – A0 : These two lines are address lines to select
A1 A0 Port Selection
the appropriate port or control word register.
0 0 Port A
(ix) D7-D0: The 8-bit data bus which carry data or
0 1 Port B
1 0 Port C control word to / from the microprocessor.
1 1 Control Word Register (CWR) (x)RESET : It is a logic high signal which clears the
CWR of 8255.
Modes of Operation of 8255: The PIO 8255 operates basically in two modes, i.e., I/O mode and Bit Set Reset
(BSR) mode. In the BSR mode only port C can be used to set or reset its individual bits. The input/output ports
can be programmed in I/O mode of operation of 8255. Further there are 3 modes of I/O mode of operations
namely, mode 0, mode 1 and mode2.
BSR Mode: In this mode, any of the 8-bits of port C can be set or reset depending on B 0 of the control word
register(CWR). The bit to be set or reset is selected by bit select flags B 3, B2, and B1 of the CWR as given in
Table. The control word format is shown in Fig.3.3.
Page no: 2
Table : Bit Select Flag configuration
B3 B2 B1 Selected Bits of Port C
B7 B6 B5 B4 B3 B2 B1 B0
0 0 0 PC0
0 X X X 0 0 1 PC1
0 1 0 PC2
0 1 1 PC3
0-For BSR mode Bit Select Flag 1 0 0 PC4
1 0 1 PC5
0-Rest ; 1- Set 1 1 0 PC6
Fig.3.3 : BSR mode control word register format 1 1 1 PC7
I/O Modes : There are three modes of I/O mode of operation. They are mode 0, mode 1, mode 2.
Mode 0 (Basic I/O Mode) : This mode is also called as Input / Output mode. This mode provides input and
output capability using each of the three ports. The features of this mode are as follows
Two 8-bit ports (Port A & B) and two 4-bit ports of Port C are available. The two 4-bit ports can be
combinedly used as a third 8-bit port.
Any port can be used as input or as latched output.
A maximum of four ports are available so that overall 16 I/O configurations are possible.
The modes of each of the port can be selected by programming a control word register. The B7 bit of the
CWR validates the I/O modes of operation and then reset of the bits shown the different modes of operation
as shown in the Fig.3.4 .
Mode 1 (Strobed I/O Mode) : This mode is known as strobed input/output mode. In this mode the
handshanking signals control the input / output action of the specified port. The features of this mode are as
follows
Two groups A & B are available for data transfer with handshanking
Group A includes 8-bit Port A and as I/O port along with 4-bit of Port C as control/data port. Group B
includes 8-bit Port B and as I/O port along with 4-bit of Port C as control/data port.
PC0 – PC2 are used to generate control signals for port B and PC3-PC5 are used to generate control signals
for port A. PC6 & PC7 may be used as independent data lines.
Input Control Signal Definitions (Mode 1):
STB (Strobe Input): When this signal is low, the 8-bit data available in input is loaded into
input latches. The pin PC4 in group A and PC2 in group B generates this handshake signal.
Page no: 3
IBF (Input buffer full): Once the data is loaded into the latches this signal rises to logic ‘1’. PC5 in group A
and PC1 in group B this acts output acknowledge signal.
INTR (Interrupt request): This is active high output signal which can be used to interrupt the CPU
whenever an input device requests the service. PC3 for group A and PC0 for group B is used.
Problem Statement:
Interface an 8255 with 8086 to work as an I/O port. Initialize port A as output port, port B as input port and
port C as output port. Port A address should be 0740H. Write a program to sense switch positions SW0-SW7
connected at port B. The sensed pattern is to be displayed on port A, to which 8 LEDs are connected, while
the port C lower displays number of on switches out of the total eight switches.
Solution:
The control word is decided upon as follows:
B7 B6 B5 B4 B3 B2 B1 B0
1 0 0 0 0 0 1 0
Port-B
I/O Port-A in Mode Port-A, Port-C, Port-B, Port-C,
Mode
Mode 0 O/P O/P I/P O/P
0
Control word = 82 H
Address line bit A0 of the microprocessor is used to select the lower order data bus. Hence any changes in
this bit will not affect the selection of the ports. Therefore A2 and A1 of the microprocessor address bits are
used to select the ports and connected to A1 and A0 of 8255 IC. The address mapping table is as shown in
below.
Page no: 4
The 8255 port addresses are tabulated as shown below.
Page no: 5
MOV DX, 0786H
MOV AL, 82H Initialize CWR with control word 82H
OUT DX, AL
SUB DX, 04H Get address of port B in DX
IN AL, DX Read port B for switch positions in to AL
SUB DX, 02H Get port A address in DX.
OUT DX, AL Display switch positions on port A
MOV BL, 00H Initialize BL for switch count
MOV CH, 08H Initialize CH for total switch number.
above: ROL AL
Rotate AL through carry to check whether the
JNC below
switches are ON or OFF i.e., either 1 or 0.
INC BL
Below: DEC CH Check for next switch. If all switch are
checked, the number of ON switches are
JNZ above
in BL.
MOV AL, BL
ADD DX, 04H Display it on port C,
OUT DX, AL
HLT Stop
Page no: 6