Professional Documents
Culture Documents
ADuC832
PORT
Display
Introduction
The I/O (Input/Output) interface permits the
microprocessor to communicate with the outside
world, eg to control an external device
How can you connect a keyboard, or a mouse, to a
8086 or P6 microprocessor?
The 8086 microprocessor can only access external
components (including memory devices) via the
address and data buses
Concept of I/O
The mechanism is similar to the memory
interface because the CPU is using the same
set of buses data and address
Data transfer still takes place over the
multiplexed address/data bus
Minimum-mode interface
To connect to external I/O devices, usually some
interface circuits are required
Interface circuitry is used to bridge the
microprocessor and the I/O (Input/Output) devices
Functions of the interface select the I/O port
(decoding), latch output data, adjust the signal
levels etc
Only address/data lines from 0-15 are used for
interfacing with external I/O devices
I/O Ports
I/O Port addresses (16-bit) (or Port numbers )
are generated by the 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
M/IO signal is set to 0 to indicate I/O
operations (this is the only different
between read/write of an I/O and memory)
COM1
COM2
CGA adapter
LPT1
Hard disk
8255 (PPI)
Timer
Interrupt controller
DMA controller
I/O instructions
How to read/write to/from I/O devices?
In 8086, IN and OUT are I/O instructions
IN - input from port into AL or AX
OUT - Output from AL or AX to port
IN AL, FF (move a byte in from port FF)
OUT FF, AL (move a byte out from AL)
IN and OUT are called direct instruction to access
I/O ports
Using IN, or OUT the max. port no. is 255 (FF)
I/O instructions
Example
Data are to be read in from two byte-wide input ports at address
AA and A9, respectively, and then output as a word to a word-wide
Output port at address B000. Write a sequence of instructions to
Perform this I/O operation
IN
MOV
IN
MOV
OUT
AL, AA
AH,AL
AL,A9
DX, B000
DX, AX
AH
AL
Data from AA Data from A9
Decoder
I/O
Example
Refer to the previous diagram
To which port are data being written when
the address put on the bus during an output
bus cycle is 8002(Hex)
How to output the byte contents of the
memory location called DATA to output
Port 0 by simple assembly language?
To/From
CPU
To/From
I/O
devices
8255 PPI
It consists of 3 ports
Each port is 8-bit
Address A0 and A1 (these are input of 8255 not
8086) are used to select the port to read/write
Data are transferred through a 8-bit bidirectional
data bus
Chip select (/CS) of the 8255 must be enabled
Register-Select Code
The microprocessor must apply this code to
the register-select inputs A0 and A1 of the
8255A.
Select Code
A1 A0
00
Port A
01
Port B
10
Port C
11
Control Register
8255 PPI
An 8255 PPI will occupy at least 4 I/O
addresses
The A1A0 of the 8255 usually connected to
address lines of the CPU. Therefore,
changing the 0, 1 of the lines can provide
different port numbers
8255 decoding
Decoder
Address
If Port A is 1238H
and Port B is 123AH
Can you identify which
Two address lines are
Connected to A1A0?
8255
8086
/CS
A1
A0
Example
If PortA occupies location 1238H and PortB
occupies 123AH, can you determine addresses
occupied by other Ports? What address lines
are connected to A1A0 of the 8255?
0001 0010 0011 1000 (1238H) look for 00 Port
A
0001 0010 0011 1010 (1238H) look for 01 Port
B
Example
Determine
Port
Occupied
By the 8255
To/From
CPU
To/From
I/O
devices
8255 PPI
To program the 8255, A1A0 = 11 and a
write cycle is initialized so that the proper
bit pattern is written to the control register
After the configuration then the PORTs A,
B, C can be used accordingly
Group B
D1
Port B
D2
D3
Mode selection
Group A
D4
Port C upper
Port A
D6, D5
D7
Port C lower
Mode selection
Command type
Output
Input
Output
Input
Mode 0
Mode 1
Output
Input
Output
Input
00
Mode 0
01
Mode 1
1X
Mode 2
Bit set/reset
Mode set
Control Bits
D0 set input/output for lower 4-bit of Port C (1
for input; 0 for output )
D1 set input/output for 8-bit of Port B
D2 mode selection (0 mode 0; 1 mode 1)
D3 same as D0 but for upper 4-bit
D4 same as D1 but for Port A
D6 & D5 mode selection (00 mode 0, 01
mode 1, 1X mode 2)
D7 mode set flag ( 1- active)
Mode Selection
Mode set flag is the D7 bit in the control, it must
be at logic 1 whenever the mode operation is to be
changed. There are three modes of operation
which are known as mode 0, mode 1, and mode 2
respectively.
We will only discuss Mode 0 and Mode 1!!!!
But you should study Mode 2 by yourself!!!!!!!
Example
If control register is at Port 20H
How to configure the 8255 in Port A Mode 0
input and Port B and C mode 0 output ?
Identify the control pattern 10010000 (90H)
Move this to the port
MOV AL, 90H
OUT 20H, AL
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
The binary pattern is 10000010 (82H) refer to the table of control word
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
Exercise
If port A is F0H, Port C is F4H
First configure PortA mode 0 output and
PortB mode 0 input
Then use a loop to send 10 character via
port A and read 1 byte from port B
8255
Device
Points to note
Need a signal to store data into the latch
Need to inform CPU data is available
Need to inform external device data is full
Need to know when data is read then reset
the buffer
Example
If the control register is loaded with 10111XXX. What is the
Configuration for the 8255?
Port A is in mode 1 input port
Upper 4-bit of Port C is reconfigured to provide the Port A
Control/data lines
PC4 strobe input (/STBA) (to strobe data in Port A into the latch)
(1 -> 0)
PC5 input buffer full when 1 (IBFA)
(output to signal external device)
PC3 interrupt request (INTRA) (used when action should be
performed by the microprocessor ) (output)
PC6,7 I/O
PCx PC (Port C bit x )
Strobe input
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.
Strobed input port captures data from the port when the /STB
is activated.
The /STB signal (1->0) causes data to be captured and it activates
the IBF (Input Buffer Full) and INTR (Interrupt Request).
IBF (a 1) indicates that data are in port A.
Once the microprocessor notices that data are strobed into the port,
it executes an IN instruction to read the port.
Strobe Input
The above will show the purpose of the INTE (interrupt enable)
If you want INTR to be active, what should you put in INTE?
Strobed output
Data are written to a port
/OBF output buffer full
/OBF becomes a logic 0 to indicate data are
present (1->0)
External device removes the data by
strobing (1->0) the /ACK input to the port
The /ACK returns the /OBF to logic 1 this
will clear the INTR as well
Mode 1 Output
Example
When control register is 1010XXXX then Port A is set to output
PC7 output buffer full (/OBF) (output)
When this is active (low) implying data are available at the port
Outputs. Data are written by the microprocessor
PC6 acknowledge (/ACK) (input)
This is input by external device after reading the data at the port
This signal also reset the /OBF with its low going edge
PC3 interrupt (output) (INTR)
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
Mode 1 Output
Points to consider
When using in Mode 1 output mode
CPU should monitor which bit?
External device should monitor which bit?
Example
Mode 2
Mode 2 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 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
Mode 2 Bi-directional
Mode 2
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
PC3 interrupt (output) (active high)
PC2-0 general purpose I/O pins and controlled by the bit set
and reset command
Bi-direction operation
First test the /OBF (output buffer full)
signal to test if output buffer is empty
Buffer is empty then sent data to output
buffer (using OUT instruction)
External device monitors the /OBF signal to
decide whether data is available
If /OBF is 0 then sends /ACK to remove the
data
Example
Tran:
IN
Test
JZ
mov
OUT
AL, PortC
AL, bit7
Tran
AL, AH
PortA, AL
Bi-directional operation
To read data, test IBF (Input Buffer full)
If IBF=1, data are input using the IN
instruction
External device sends data using /STB
IBF is clear when microprocessor doing the
IN
Write a simple program to read data from
PortA
Example
Read:
IN
test
JZ
In
AL, PortC
AL, Bit5
Read
AL,PortA
Example
If control register is 00001111
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?
In Mode 1, the bits of Port C not used for control
can only be written by the set/reset feature
3
Different
Modes
of
8255A
Self test
What is the major function of 8255
How to configure the 8255
Differences between the different operating
modes (mode 0 and mode 1)
What is the bit set/reset feature
When should you use the bit set/reset
feature
Application of 8255
8255
Printer
PB
D0-D7
PC4
Strobe
PC2
ACK
Example
Transfers ASCII character from AH to the printer via port B
PortC equ 62H
PortB equ 61H
CMD equ 63H
Print:
IN AL, PortC
AND AL, #00000010B
; test if buffer is full
JZ Print
mov AL, AH
out
portB, AL
mov AL, 8
; send a strobe
out
CMD, AL
mov AL, 9
out
CMD, AL
Printer Interface
Example
Refer to the diagram for the 16-bit 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 addressed?
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
8255 Parallel
I/O for
386(Contd)
Accesses port C
8255 Direct
I/O Connection (Contd)
Memory
I/O
Total
1M
I/O 64K
Memory
Traditional setup
Memory mapped IO
8255 PIO
Example
Which I/O port is selected for operation when the memory address
Output on the bus is 00402 hex? (Refer to previous diagram for
memory mapped I/O (16-bit))
A10 = 1 and A0 =0 will enable the lower address decoder
A5A4A3 = 000 selects the PPI 0
A2A1 = 01 select Port B
Applications of 8255
Using a 8255 to derive 8 7-segment display
Port A is used as output to determine the pattern
Port B is used to enable the different 7-segment unit
Application of 8255
Using a 8255 to drive a LCD display
Port A supplies command and data (8-bit)
Port B supplies the control signals (only 3 bits are used)
Application of 8255