3.IO and Device Interfacing
3.IO and Device Interfacing
In addition to memory, 80x86 microprocessors are able to access I/O ports. Ports are
accessed either to bring data from the port into the CPU (inputting) or to send data from
the CPU to the port (outputting).
In format (1) above, port# is the address of the port, and can be from 00 to FFH. This 8
-bit address allows 256 input ports and 256 output ports. No segment register is
involved in computing the address, in contrast to the data accessed from memory.
In format (2), port# is the address of the port, and can be from 0000 to FFFFH. This 16-
bit address allows 65,536 input ports and 65,536 output ports. No segment register (DS)
is involved.
Ex: Write a sequence of instructions that will output FFH to a byte-wide output
port at the address ABH of the I/O address space?
MOV AL,FFH
OUT ABH,AL
Ex: Write a sequence of instructions that will output FFH to an output port at
the address B000H of the I/O address space?
MOV DX,B000H ;Note that 16-bit address must be in DX
MOV AL,FFH
OUT DX,AL
Ex: Assume that the port address 22H is an input port for monitoring the
temperature. Write Assembly language instructions to monitor the port
continuously for the temperature of 100 degrees. If it reaches 100, then BH should
contain ‘Y’.
Ex: Assume that AX=98F6H and the output port address is 47H, then
OUT 47H,AX
In the above case F6H, the content of AL, goes to port address 47H and 98H, the
content of AH goes into the port address 48H.
In other words the low byte goes to the low port address, and the high byte goes
to the high byte address.
Page 2
The 8255 PPI chip is designed to permit easy implementation of parallel I/O into the
microcomputer. The 8255 is one of the most widely used I/O chips. It has three
separately accessible ports, A, B, and C. Above all the user can program the individual
ports to be input or output, and change them dynamically.
Page 3
Detailed Block Diagram of 8255 (a), and the Pin layout (b)
• PA0-PA7 (Port A) : This 8-bit port can be programmed all as input or all as
output or all bits asbi-directional input/output.
• PB0-PB7 (Port B) : This 8-bit port can be programmed all as input or all as
output or all bits as bi-directional port.
• PC0-PC7 (Port C) : This 8-bit port can be all input or all output. It can also be
split into two parts:
CU (Upper 4 bits PC4-PC7) and
CL (Lower 4 bits PC0-PC3).
Each can be used for input or output.
• RD & WR: These two active low signals are inputs to the 8255. If the 8255 is
using isolated I/O design, IOR or IOW of the system bus are connected to these
two pins. If the port uses memory-mapped I/O, MEMR and MEMW activate
them.
• RESET: This is an active high signal input to the 8255 used to clear the control
register. When RESET is activated, all ports are initialized as input ports.
• A0, A1, and CS: While CS selects the entire chip, it is A0 and A1 that select
the specific port. A0 and A1 are used to access ports A, B, C, or the control
register according to the table below.
Page 4
A1 A0 Selects:
0 0 Port A
0 1 Port B Table 1:
1 0 Port C
1 1 Control Register
Ex: Configure 8255 as follows: port A as input, B as output, and all the bits in C as
output. Determine the content of the Control Register and,
Program the ports to input data from A and send it to both B and
C. (Assume the standard port addresses of 8255 given above)
1 0 0 1 0 0 0 0 = 90H
Page 5
Ex: Configure the ports of 8255 as follows: port A=input, B=output/ PC0 –PC3=input, and
PC4-PC7=output.
Determine the content of the Control Register and,
Program the 8255 to get data from port A and send it to port B. In addition, input data
from PCL and send out to PCU.
1 0 0 1 0 0 0 1 = 91H
Page 6
The 8255 programmable Peripheral Interface (PPI)
Page 7
1
Page 8
2
Page 9
3
Page 10
4
Page 11
5
Page 12
6
Page 13
7
Page 14
8
Page 15
9
Page 16
10
Page 17
11