Lecture8-80x86 IO Interfacing
Lecture8-80x86 IO Interfacing
Seyed-Hosein Attarzadeh-Niaki
Review
• Memory and memory interfacing
– Memory chips
– Address decoding
– Data integrity
– 8086 memory interfacing
1
10/20/2024
Outline
• IO interfacing
– Basic IO interfacing
– 8255 programmable peripheral interface
– 8253 programmable interval timer
2
10/20/2024
I/O Example
‘Y’
3
10/20/2024
4
10/20/2024
5
10/20/2024
Data
Data Registers External
Device
Data Status
Interface
Lines
Logic
Status/Control Registers Control
Address
Lines Data
External
I/O Device
Logic Status
Interface
Control Logic
Lines Control
6
10/20/2024
PA3 1 40 PA4
Internal Data Bus
PA2 2 39 PA5
PA1 3 38 PA6 Group A PA7~PA0
37 PA7
Group A
PA0 4 Control
RD 5 36 WR Port A
CS 6 35 RESET
D0~D7
GND 7 34 D0 Data Bus PC7~PC4(3)
Group A
A1 8 8255 33 D1
Buffer Port C
A0 9 32 D2 (upper bits)
PC7 10 31 D3
RD
11 30 D4
PC6 WR Read/ Group B PC3(2)~PC0
PC5 12 29 D5 A0 Port C
D6
Write
PC4 13 28 A1 (lower bits)
PC0 14 27 D7 CS
Logic
PC1 15 26 Vcc RESET
PB7~PB0
PC2 16 25 PB7
Group B Group B
PC3 17 24 PB6 Port B
23 PB5 Control
PB0 18
PB1 19 22 PB4
PB2 20 21 PB3
Microprocessors and Interfacing 13
7
10/20/2024
Group A PA7~PA0
Group A
Control Port A
and 8255 WR
A0
Read/
Write
Group B
Port C
PC3(2)~PC0
A1
• Bidirectional, tri-state, 8-bit
(lower bits)
CS
Logic
RESET
PB7~PB0
Group B Group B
Control Port B
1 × × 1 1 D0~D7 in float
Operation Modes
• Input/output modes
– Mode 0, simple I/O mode:
• PA, PB, PC: PCU{PC4~PC7}, PCL{PC0~PC3}
• No Handshaking: negotiation between two entities before communication
• Each port can be programmed as input/output port
– Mode 1:
• PA, PB can be used as input/output ports with handshaking
• PCU{PC3~PC7}, PCL{PC0~PC2} are used as handshake lines for PA and PB, respectively
– Mode 2:
• Only PA can be used for bidirectional handshake data transfer
• PCU{PC3~PC7} are used as handshake lines for PA
8
10/20/2024
1 D6 D5 D4 D3 D2 D1 D0
– BSR mode
0 D6 D5 D4 D3 D2 D1 D0
9
10/20/2024
Select Input/output
Mode Examples
1. Write ASM instructions for setting the 8255 in simple I/O mode with PA
and PB being output port and PC being input port.
MOV AL, 10001001B
MOV DX, ControlPort
OUT DX, AL
2. Assume that the address of the control register of the 8255 is 63H, give
out the instructions that set up the 8255 in mode 0 where PA, PB and PCU
are used as input ports and PCL is used as output port.
MOV AL, 10011010B
OUT 63H, AL
10
10/20/2024
Next Lecture
• 8086 Interrupts
SPARE SLIDES
11
10/20/2024
Simplified Structure of a
Timer/Counter
12
10/20/2024
13
10/20/2024
Internal Structure
14
10/20/2024
Write/Read Operations
• WRITE
– Write a control word into control register
– Load the low-order byte of a count in the counter register
– Load the high-order byte of a count in the counter register
• READ
– Simple Read: two I/O read operations, first one for low-order byte and
then one for the high order byte
– Counter Latch Command: one I/O write operation used to write a
control word to the control register to latch a count in the output
latch, then two I/O read operations are used to read the latched count
as in Simple Read.
➢ Read-Back Command: for 8254 only
15
10/20/2024
Operation of 8253
• 8253 takes one CLK pulse
to convey the count from
CR to CE
• CE will start to count only
when GATE = 1
– When to check the GATE?
On every CLK pulse’s rising
(0-to-1) edge
– When to count down?
On every CLK pulse’s falling
(1-to-0) edge
Modes of Operation
• Mode 0: Interrupt
on Terminal Count
• Mode 1: Hardware
Retriggerable One-
shot
• Mode 2: Rate
Generator
• Mode 3: Square
Wave Rate
Generator
• Mode 4: Software
Triggered Strobe
• Mode 5: Hardware
Triggered Strobe
Microprocessors and Interfacing 32
16
10/20/2024
17
10/20/2024
Programming Example
Example:
Setting Up a Counter
18
10/20/2024
Example
• The frequency of CLK is
2MHz, write initiation program D7~D0 D7~D0 OUT0
to let counter 0 generate an OUT1
IOR RD OUT2
interruption request after IOW WR GATE0
100μs, let counter 1 generate A1 A1
GATE1
A0 A0
50% duty cycle square wave GATE2
IOR &
with a period of 10μs, and let IOW
G 8253 CLK0
CLK1
counter 2 generate a negative A15 & CLK2
G2A
~
pulse every 1ms. A8 CS
A2 74LS138
A7 +
A6 G2B Y0
A5 A
A4 B
A3 C
19
10/20/2024
20
10/20/2024
Mode 1:
Hardware Retriggerable One-shot I
• Normal Operation:
– The output will be initially high after the mode set
operation;
– The output will go low on the CLK pulse following
the rising (0-to-1) edge of the gate input;
– The output will go high on the terminal count and
remain high until the next rising edge of the gate
input.
– Output: one-shot of N clock pulses on every
trigger
21
10/20/2024
Mode 1:
Hardware Retriggerable One-shot II
• Retriggering:
– retriggerable, hence the output will remain low for
the full count after any rising edge of the gate input
• New count:
– If the counter is loaded during one shot pulse, the
current one shot is not affected unless the counter is
retriggered
– If retriggered, the counter is loaded with the new
count and the one-shot pulse continues until the new
count expires
Microprocessors and Interfacing 43
Mode 1:
Hardware Retriggerable One-shot III
22
10/20/2024
23
10/20/2024
Mode 3:
Square Wave Rate Generator I
• Normal Operation:
– The output will be initially high;
– For even count, counter is decremented by 2 on the falling edge of each clock
pulse; when reaches terminal count, the state of the output is changed and
the counter is reloaded with the full count and the whole process is repeated
– For odd count, the first clock pulse decrements the count by 1. Subsequent
clock pulses decrement the clock by 2. After timeout, the output goes low and
the full count is reloaded. The first clock pulse (following the reload)
decrements the count by 3 and subsequent clock pulse decrement the count
by two. Then the whole process is repeated.
– Output: if the count is odd, the output will be high for (n+1)/2
counts and low for (n-1)/2 counts.
24
10/20/2024
Mode 3:
Square Wave Rate Generator II
• Gate disable:
– If Gate is 1 counting is enabled otherwise it is disabled.
– If Gate goes low while output is low, output is set high immediately.
After this, When Gate goes high, the counter is loaded with the initial
count on the next clock pulse and the sequence is repeated.
Mode 3:
Square Wave Rate Generator III
• New count:
– The current counting sequence is not affected when the new count is
written.
– If a trigger is received after writing a new count but before the end of
the current half-cycle of the square wave, the counter will be loaded
with the new count on the next CLK pulse and counting will continue
from the new count.
– Otherwise, the new count will be loaded at end of the current half-
cycle.
25
10/20/2024
Mode 4:
Software Triggered Strobe I
• Similar to mode 2 except that the counter is not
auto-reloaded
• Normal Operation:
– The output will be initially high;
– The output will go low for one CLK pulse after the terminal count
• Gate disable:
– If Gate is one, the counting is enabled; otherwise, it is disabled
• New count:
– If a new count is written during counting, it will be loaded on the next CLK
pulse and counting will continue from the new count. If the count is two
byte then:
• Writing the first byte has no effect on counting
• Writing the second byte allows the new count to be loaded on the next CLK pulse
Automatically repeat
26
10/20/2024
27