Professional Documents
Culture Documents
Introduction
In addition to memory, a computer system must also provide interfaces with other
external devices, such as display unit, keyboard etc. All these external devices are
regarded as Input/Output devices (usually we simply use the term I/O). In general,
memory can also be considered as some kinds of I/O from the CPUs point of view.
The I/O (Input/Output) interface permits the microprocessor to communicate with the
outside world. How can you connect a keyboard, or a mouse, to an 8086 microprocessor?
In the 8086 microprocessor, I/O devices are connected via the address and data buses
and the mechanism is similar to the memory interface. Data transfer takes place over the
multiplexed address/data bus.
The above figure shows how the I/O devices are connected to the system. As you can see
the major difference between connection to a memory and connecting to I/O devices is
the signal level of M/IO. When accessing memory devices M/IO is 1. While M/IO is
0 when accessing I/O devices.
Similar to memory devices, as there are many I/O devices connected to the buses
therefore, decoding is also required for I/O system.
The 8086 minimum mode I/O interface
Interface circuitry, as depicted in Figure 7.1, is used to bridge the microprocessor and the
I/O (Input/Output) devices. Functions of the interface are to select the I/O port, latch
output data, adjust the signal levels etc. Only address/data lines from 0-15 are used (but
for memory devices address lines A0 to A19 are used.) In addition, the I/O interface
circuit is also similar to the memory decoder.
I/O address space
Unlike the 89C51, or the ADuC832, there are no I/O ports available in the 8086. All
I/O devices are connected to the address bus and data bus. However, we still use the
term I/O port to describe the connection between the 8086 and an I/O device. Since only
address lines A0 to A15 are used by I/O devices so a total of 64K devices can be
connected to the system. Imagine there are virtual I/O ports then the ports are numbered
from 0 to 64K-1. Similar to memory devices, byte is the basic unit for data transfer so if
an I/O device transfers 16-bit data then it will occupy 2 ports. So I/O ports could be 8-bit
or 16-bit.
I/O port number (16-bit) are generated by microprocessor via the ADn lines and after
proper decoding, correct I/O port can be selected. AD16 to AD19 are held at 0 for I/O
operations.
Software for accessing I/O ports
When accessing memory, we use move (MOV) operations. When accessing I/O port,
we use IN and OUT. There are two forms of IN OUT instructions: direct and indirect.
In Direct instruction, we can address 256 ports (8-bit) only. The format of IN OUT is:
AL, AA
AH,AL
AL,A9 ; now the data becomes 16-bit and stored in AX
DX, B000
DX, AX
; can I do OUT B000, AX instead ??????
Since the port number B000 is larger then 8-bit so indirect is used.
I/O bus cycle
Accessing I/O devices are very similar to accessing memory therefore, to read/write data
to or from an I/O device, a proper cycle is performed. A read cycle for I/O also takes 4
cycles and the signals are very similar to the memory read cycle except the M/IO signal.
Input cycle (you should compare this with the memory read/write cycle)
To/From
PortA
To/From
PortB
8255A
To/From
CPU
To/From
PortC
Referring to the block diagram, you can see that the 8255 is similar to a multiplexer with
1 interface with the CPU but 3 interfaces with I/O devices. Therefore, there must be
some selection mechanism so that data can be channeled to the proper Port. This is
achieved via the 2 input control (A0 and A1).
Address A0 and A1 (these are input of 8255 not 8086) are used to select the port.
Data are transferred through an 8-bit bidirectional data bus between the 8255 and the
CPU.
Chip select (/CS) of the 8255 must be enabled before you can program or access the
8255.
With 2 control bits (A0 and A1), there are 4 combinations, as shown below
Select code A1 A0
00
Port A
01
Port B
10
Port C
11
Control Register
The control bits (A0 and A1) usually come from the address lines of the CPU implying
that the 8255 will occupy at least 4 I/O ports of the computer system.
Example
If PortA occupies port location 1238H and PortB occupies 123AH, can you determine
port numbers occupied by other Ports? What address lines are connected to A1A0 of the
8255?
Consider the port number in binary form
0001 0010 0011 1000 (1238H)
0001 0010 0011 1010 (123AH)
According to the table PortA is selected when A1A0 are 00 and PortB is selected when
A1A0 are 01 so the other ports should be 123CH and 123EH (when A1A0 = 10 and 11).
The address lines used are A2A1 with A2 connected to A1 of 8255 and A1 connected to
A0 of 8255.
Connect to uP
Connect to I/O
devices
Group B
Port C lower
D1
Port B
D2
Mode selection
D3
Group A
Port C upper
D4
Port A
D6, D5
Mode selection
D7
Command type
0
1
0
1
0
1
0
1
0
1
00
01
1X
0
1
Output
Input
Output
Input
Mode 0
Mode 1
Output
Input
Output
Input
Mode 0
Mode 1
Mode 2
Bit set/reset
Mode set
no buffer to store the input data. When the external device removes the data from the
data bus then the data will be gone.
Example
What is the mode and I/O configuration for ports A, B, and C of an 8255A after its
control register is loaded with 82Hex.
According to the bit definition
The binary pattern is 1000 0010 (82H)
D0 = 0 lower 4 bits of Port C are outputs
D1 = 1 Port B are inputs
D2 = 0 mode 0 operation for both Port B and the lower 4 bits of Port C
D3 = 0 upper 4 bits of Port C are outputs
D4 = 0 Port A are outputs
D6D5 = 00 mode 0 operation for both Port A and the upper part of Port C
D7 =1 mode enable
Mode 1
Mode 1 represents what is known as strobed I/O. In this mode, the A and B ports are
configured as two independent byte-wide I/O ports, each of which has a 4-bit
control/data port associated with it. The control/data ports are formed from the lower
and upper 4-bit of port C respectively.
Both input and output are latched ie buffers available to store the input data as well
as the output data. But in Mode 0 only has buffer for output data.
Data applied to an input port must be strobed-in with a signal produced by an external
hardware.
Handshake signal is provided for an output port to coordinate the data transfer.
Handshaking represents steps that must be completed before data (or communication)
between two devices can be exchanged or transferred.
Handshake signals in 8255 represent the available of data, or when an external device has
read these data.
The 8255 is only serving as an agent or a middle-man between an external device and the
CPU. So after receiving data from a device (input) then 8255 must inform the CPU to
read the data. Similarly, after receiving data from CPU (output), it will inform the
external device to get the data.
The above diagram illustrates the application of the control bits (bits from Port C) when
the device is in Mode 1 input for PortA. The STB, IBF and INTR are used for
handshake and these bits come from PortC.
In Mode 1, the 8255 provides buffer (or store, or latch) to hold the incoming or outgoing
data. However, the buffer can only store 1-byte of data so there is a mechanism to store
the data as well as signal to inform external devices that the buffer is full!
Strobe Input (STB)
Strobed input (mode 1) causes port A and/or port B to function as latching input devices.
External data is stored in the port until the microprocessor is ready to retrieve it by
issuing a /RD signal. Referring to the above diagram, the strobe input is connected to
PC4 (Port C bit 4).
Strobed input port captures data from the port when the /STB is activated.
The /STB signal (1->0) causes data to be captured, or stored, and it activates the IBF
(Input Buffer Full) and INTR (Interrupt Request).
IBF (PC5) (a 1) indicates that data is available in port A.
Once the microprocessor notices that data are strobed into the port, it executes an IN
instruction to read the port.
The act of reading the port restores both IBF and INTR
IBF reset by the rising edge of /RD input
INTR reset by a falling edge of /RD
The operation sequence for strobe input:
1. External device put data into the port A or B
2. external device issues the strobe signal (/STB) to latch data into the port
3. 8255 issue signal IBF and INTR to the microprocessor to indicate that data is
available
The INTE (interrupt enable) is the signal for enabling or disabling the issue of the INTR
(interrupt request). As shown in the above diagram, the INTR is ANDed result of IBF and
INTE. Therefore, after data is being strobed in, the IBF is active but INTR will only be
active if INTE is enabled.
The INTE is bit 4 of Port C.
Strobed Output
Handshake signals are OBF, ACK, and INTR. Now data is being sent by the CPU via
the 8255 to external devices.
To I/O devices or uP
From I/O devices
To uP
Interrupt will be generated when data is read and external device acknowledge so signal
the microprocessor to send other data
INTR is reset when /ACK, /OBF, and INTE are 1
INTE interrupt enable and this signal must be set to 1 if you want to active the
interrupt request (INTR) to the CPU during the different I/O operations.
How does the CPU read data from the 8255?
Usually, we need to write a program to check for the available of data, refer to the
following example.
What is the purposes of the following very simple assembly codes?
Hints: consider what does Bit5 represent?
Read:
IN AL, PortC
AND AL, 0010 0000B
JZ Read
IN AL, PortA
Ret
In Mode 1 input, bit 5 of Port C is the IBF for Port A. When data is available then
IBF is 1 so after the logical AND if IBF is 1 then result is not zero so can read data
from Port A. Otherwise loop back to READ to check the bit again.
Mode 2 (Will not be examined!!!!)
Mode 2 is strobed bidirectional I/O
The port can be either inputs or outputs, depends on the /WR and /RD signals.
Only Port A can be used for this mode.
Control register is written with bit pattern 11XXXXXX.
Inputs and outputs are both latched
PC3-PC7 are used for generating/accepting handshake signals
PC2-PC0 can still be used for I/O
Operation mechanism of Mode 2
Mode 2 is the combination of INPUT and OUTPUT. This is similar to Mode 1 but now
you get both INPUT and OUTPUT operations to consider.
PC7 output buffer full (output) (low = buffer full) CPU has written data to port A
PC6 acknowledge (input) (low) acknowledges that the previous data byte is received by
the destination and the next byte may be sent by the processor
PC4 strobe (input) to strobe in the data into the input latches
PC5 input buffer full (output) (high = buffer full) used as an acknowledge that the data
has been received by the receiver
AL, PortC
AL, 10000000B
Tran
AL, AH
PortA, AL
AL, PortC
AL, 00100000
Read
; loop until data is available
AL,PortA
Example
If pattern 00001111 is written to the control register
Then the logic level to be set is 1 represented by D0
The bit to be set is 111 represented by D3D2D1 (i.e 7 in this case )
So after the control word is written PC7 is set to 1
Why want to set the bits of Port C?
The INTE (Interrupt enable) is one of the signal that can be configured using the bit
set/reset feature
The above figure illustrates the different operating modes provided by the 8255.
Example
What control word must be written to the control register of the 8255A such that Port A is
configured for bi-directional operation and Port B is setup with Mode 1 output?
Write the sequence of instructions needed to load the control register of an 8255 with the
control word C4H. Assume that the 8255 resides at address 0FH of the I/O address space.
Applications of 8255A
8255
Printer
PB
D0-D7
PC4
Strobe
PC2
ACK
Connecting to a printer via an 8255 in Mode 1 via Port B (PB). PC4 is used as control to
signal the printer that data is available and PC4 should be a 0->1 transition. PC2 is used
as acknowledge when printer read the data.
Code example based on the above hardware setup
PortC equ 62H
PortB equ 61H
CMD equ 63H ; internal control register
Print:
IN AL, PortC
AND AL, 00000010 ; test if buffer is full
JZ Print
mov AL, AH
OUT PortB, AL
mov AL, 8
; send a strobe
OUT CMD, AL ; using set/reset to send a pulse
mov AL, 9
OUT CMD, AL
Another version of sending data to printer
Code example
Refer to the diagram (figure 7.17) for the Parallel I/O setup, what must be the
address inputs of the even-addressed group of 8255 if Port C of PPI 14 is to be
chosen?
To enable PPI 14, the lower 8205 must be enabled for operation
And its 07 output switched to logic 0 (active low).
This requires enable
Input A0 = 0 and chip select code A5A4A3 = 111
A0 = 0 to enable 8205 (the even address)
A5A4A3 = 111 select PPI 14
Port C of PPI 14 is selected with A1A0 = 10
A2A1 = 10 access Port C
The rest of the address bits are dont care states
So the final pattern A19-A6 dont cares then 111100 = 0003C
Refer to the PPT file, or past exam papers for more examples on PIO.
Memory mapped I/O
In general memory is also one form of I/O! Is it possible to treat I/O devices as some
form of memory? The answer is YES and this is called memory mapped I/O.
Definition of memory mapped I/O - I/O devices are placed in memory address space of
the microprocessor. Therefore to access memory mapped I/O, you use MOVE instead
of IN/OUT. I/O ports are treated just like a memory location.
Some memory address space is dedicated to I/O purposes and can be accessed using
memory oriented instructions.
How many I/O space are available in an 8086????
The above illustrates the hardware setup for memory mapped I/O, can you identify the
major difference between memory mapped I/O system and an ordinary I/O system?
Applications of 8255
Using an 8255 to control 8 7-segment displays
Port A is used as output to determine the pattern
Port B is used to enable the different 7-segment unit
Exercises
1. An 8255 PPI is interfaced to a microprocessor. Port B occupies port number 94 and
Port C occupies 110. Determine the address lines of the microprocessor that are
connected to A0A1 inputs of the 8255.
2. A student has designed an I/O system based on the 8255 PPI. If the Port A occupies
port number 48 and Port B occupies port number 52. Write down the statements that
can configure the device such that Port A is for input and Port B is for output under
Mode 1.
If Port A is now connected to the 8-bit data input of a printer and the student has
written the following program using the polling method to send data to the printer as
well as generating a strobe. Determine feasible values (there could be more than one
correct answer) represented by the symbols AA, BB, CC, and DD.
Which pin is being used to generate the strobe?
; program to interface with the printer
; PORT addresses are the same as before
; Polling
Busy:
IN AL, AA ; Read from a PORT
AND AL, BB ; test a bit
JZ
Busy
; jump zero
MOV AL, BL
OUT 48, AL ; send data to Port A
NOP ; the following generate a pulse using bit in Port C
MOV AL, 08H
; pull /strobe low
OUT DD, AL
NOP
MOV AL, CC
; raise /strobe High
Out DD, AL
HLT
3. A student has designed an I/O system based on the 8255 PPI. If Port A occupies port
number 68 and Port B occupies port number 72. Determine the address lines that are
connected to the A0A1 inputs of the 8255.
Write down assembly language statements for configuring the device such that Port A is
used for input and Port B is for output both in Mode 1.
The following provides useful information related to the 8255 PIO
http://tams-www.informatik.uni-hamburg.de/applets/hades/webdemos/50-rtlib/60pio8255/pio.html
NOTE: in the above the question, you should based on the data flow direction shown in
Figure 2ca !!!