Lecture10 Parallel IO
Lecture10 Parallel IO
Lecture10 Parallel IO
Parallel Input/Output
Topics
Parallel Input/Output Interfacing
8086 Basic I/O Interfaces
2
Input/Output Interfacing
Peripheral Devices are I/O devices that exchange data with a CPU.
Examples : Switch, push-button, light-emitting diode (LED), monitor,
LCD screen, printer, mouse, keyboard, disk drive, sensor, motor, audio, etc.
Interface Chips are used to resolve the differences between CPU and I/O
devices.
4
Isolated
I/O Interfacing Method
The M / IO control signal of the CPU is used as a selector
between Memory chips and Input/Output chips.
Separate memory and I/O address spaces are used.
There are distinct input and output instructions.
Example 8086 Assembly language instructions : IN , OUT
M / IO
CPU CS
RAM
CS
I/O
Interface
Address Spaces in
Isolated I/O Interfacing
●
The entire memory address space is used by memory chips only.
●
There are no reseved addresses for I/O chips in memory address space,
because the I/O addresses are separated from memory addresses.
FFFFFH
1MB
Total Memory
0FFFFH
64KB
I/O chips
00000H 00000H
Port Map in
Isolated I/O Interfacing
●
The bytes of data in two consecutive I/O addresses could be accessed
as either byte-wide data, or as word-wide data.
●
Example: I/O addresses 0000h, 0001h, 0002h, 0003h can be treated as
independent byte-wide ports 0, 1, 2 and 3.
●
Or they can be treated as as word-wide ports 0 and 1.
Memory-Mapped
I/O Interfacing Method
The M / IO control signal is not used.
Memory and I/O addresses share common address space.
There are no specific input/output instructions.
Usual memory load/store instructions are used.
Example 8086 Assembly language instruction : MOV
Address Spaces in
Memory-Mapped I/O Interfacing
●
There is a reseved address range in the memory space for the I/O chips.
FFFFFH
64KB
64K
I/O Reserved for I/O
Memory
(ROM &
RAM
00000H
Example: Memory Mapped I/O Interfacing
Example: 4 memory addresses are reserved (ded cated) for Input-Output register addresses.
Suppose the memory addresses from 0000h to 0003h are reserved for I/O reg sters.
The NAND gate can be used on address l nes A15 - A2 for ch p select ons (RAM or I/O).
For I/O reg ster select ons w th n the I/O nterface ch p, A0 and A1 l nes can be used.
(Alternat ve method:
An Address Decoder can be
used, nstead of NAND gate.)
A15 - A2
RAM
CPU NAND CS
A1
CS
I/O
Interface A0
Reserved addresses for I/O nterface ch p:
Address A15 A14 A13 A12 A11 A10 A9 A8 A7 A6 A5 A4 A3 A2 A1 A0
(Hex)
0000h 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Address Map Used by
0001h 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1
0002h 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0000h - 0003h I/O
11
12
Input/Output Transfer
Synchronization
The tasks of the interface chip are :
Synchronizing data transfer between CPU and Interface chip (Control signals).
Also between Interface chip and I/O device (Handshaking signals).
Control Handshake
s gnals s gnals
Interface I/O
CPU
Ch p Dev ce
Data Bus
Address Bus
13
14
Programmed I/O
(Polling method)
Input Operations :
Microprocessor checks a status bit of the interface
chip, to find out whether the interface has
received new data from input device.
Output Operations :
Microprocessor checks a status bit of the interface
chip, to find out whether it can send new data to
interface chip.
15
Output Operations :
Interface chip interrupts the microprocessor,
whenever it can accept new data from microprocessor.
16
Parallel Communication
In parallel communication, all bits are transferred at the same time.
Each bit is transferred along its own line.
In addition to eight parallel data lines, other lines are used to read status
information and send control signals.
Ready s gnal
D7
Transm tt ng Rece v ng
S de S de
D0
Example: Synchronization of
two parallel computers
Transmitter and receiver interfaces use handshaking protocol.
Transmitter initiates 2-wire handshaking
DV low indicates new data is available.
DR low indicates that receiver has read the data.
18
Basic Parallel Input Interface
The basic input device (to the microprocessor) is a set of tri-
state buffers.
When data is coming in by way of a data bus (either from port
or memory) it must come in through a three-state buffer.
Tri-state buffer chips can be used as input interface.
(Example chip: 74244)
Output pins of interface are connected to Data Bus of CPU
(as input of CPU).
Input pins of interface are connected to an input device.
19
D7
. D7
.
Input Device
.
Basic
Input
CPU Interface
D0
D0
CLOCK
CS
Address (control s gnal)
Decoder SELECT
20
Basic Input Interface Timing Diagram
1) Address placed on address bus at the falling edge of clock.
CLOCK
ADDRESS
R/W
DATA
21
22
Basic Parallel Output Interface
D7
. Q7
. .
Output Device
Basic
.
Output
CPU Interface .
D0 .
Q0
R/W
Address Bus
CLK
HOLD
Address
Decoder SELECT
23
ADDRESS
SELECT
R/W
HOLD
24
Topics
Parallel Input/Output Interfacing
8086 Basic I/O Interfaces
25
26
Parallel I/O Interface Chips
for 8086 CPU
Generic Name Chip Number I/O Direction Usage
74374
Latch Output only
(or 74373)
74244
Buffer Input / Output
(or 74245)
Programmable
8255 Input / Output
Peripheral Interface
27
28
Ports
Ports are:
●
Registers (part of the I/O interface chip)
●
Can be 8, 16, or 32 bits wide
●
Addressed in the range 0000-FFFFh
●
Accessed with Assembly instructions IN, OUT
29
IN Instruction
●
The IN instruction copies data from a peripheral device port to the AL or AX register.
●
If an 8-bit port is read, the data will go to AL.
●
If a 16-bit port is read, the data will go to AX.
●
IN instruction does not change any flag.
●
IN instruction has two possible formats, fixed port and variable port.
●
FIXED PORT FORMAT: The 8-bit address of a port is specified directly in the instruction.
Up to 256 possible ports can be addressed.
30
IN Instruction
●
VARIABLE-PORT FORMAT: The port address is loaded into the DX register
(Indirect Addressing) before the IN instruction.
●
Since DX is a 16-bit register, the port address can be any number
between 0000H and FFFFH.
●
Therefore, up to 65,536 ports are addressable in this mode.
●
The variable-port IN instruction has advantage that the port address
can be computed, or dynamically determined in the program.
31
Example: IN Instruction
●
Suppose that the port address 13H is an input port for
monitoring the temperature.
●
A sensor input data can be read from that port.
●
Write the Assembly language looping instructions to monitor
the port continuously for the temperature of 100 degree.
●
If temperature 100, then store 1 to the BH register.
OKU:
IN AL, 13H ;Get the temperature data from port# 13H
CMP AL, 100 ;Is temperature =100?
JNZ OKU ;If not, keep monitoring
●
Example: Interfacing input devices like switches require buffers.
33
74244
Buffer
To From
8086 Input
CPU Device
34
OUT Instruction
●
The OUT instruction copies a byte from AL or a word from AX to the specified port.
●
OUT instruction does not change any flag.
●
Similarly to IN instruction, the OUT instruction has two possible forms,
fixed port and variable port.
●
FIXED PORT FORMAT: The 8-bit port address is specified directly in the instruction.
●
Up to 256 possible ports can be addressed.
35
OUT Instruction
●
VARIABLE PORT FORMAT: The OUT instruction copies , content (data) of AL or AX
to the port at an address contained in DX.
●
The DX register must be loaded with the desired port address,
before this form of the OUT instruction is used.
36
Output Latching
Reason for latching:
Any microprocessor-based system when data is sent out by processor,
the data on the data bus must be latched by the receiver/output
●
device.
●
Memory chips have internal latches store data.
●
Latching system must be designed for I/O ports.
Data provided by the processor is available only for short period of
time 50 1000 ns) data must be latched else it will be lost.
●
●
Example: Interfacing output devices like LEDs require latches.
37
From To
74374
8086 Output
Latch
CPU Device
G: Gate enable
OE: Output Enable
38
Basic Output Interface
with 74374 Latch chip
●
The 74374 chip is a three-state Octal (8 bit) D-type Latch.
●
It can be used for output.
●
Suppose 8 LEDs (Light Emitting Diodes) are connected
to the latch chip.
●
The latch chip is connected to the 8086 CPU.
●
Isolated I/O interface method will be used.
●
Suppose the fixed port address of the Latch chip is 00004h.
●
For address decoding, logic gates (NAND) will be used.
●
Draw the block diagram hardware design showing
the connection signals and address decoding circuit.
39
Internal Diagram of
74374 Latch chip
●
The D-Latch chip has 8 inputs (D1-D8), and 8 outputs (Q1-Q8).
●
CLOCK pin is used as chip enable signal.
●
Output Control pin is connected to ground.
40
Application Example1: LEDs Blinking Program
M / IO
Address 74374 Latch chip is used to drive 8 LEDs
WR
●
Lines port
current on each LED.
A2 (04h)
8086
A3-A15 Output Select
(Minimum
CLK Q0
D0
Mode)
D0 Q1
D1 D1 Q2
74374
D2 D2 Q3
D3 D3 Q4
D4 D4 (Latch) Q5
D5 D5 Q6
D6 D6 Q7
D7 D7
Data OC
Bus
Output
Control 41
42
LEDs Blinking Program
Part-1
; Program for Blinking (Flashing) all LEDs.
; (With 74374 Latch chip)
; In Emu8086, all 12 traffic lights are turned on and off endlessly.
.model small
.data
Cumle DB 'CIKMAK ICIN BIR TUSA BASINIZ',13,10,'$'
.code
BASLA PROC
.STARTUP
mov dx, OFFSET Cumle ;Move address of Cumle variable to DX
mov ah, 09h ;Function code for displaying string
int 21h
43
Part-2
MainDongu: ;Endless main loop
mov ax, 0FFFH ;Turn all LEDs on
out 4, ax ;Fixed address of output port is 4.
.EXIT
BASLA ENDP
44
LEDs Blinking Program
(Using Emu8086 Emulator)
●
Run the LEDs program in Emu8086 emulator.
●
Open the Virtual Devices --> Traffic_Lights.exe program.
●
By default, Emu8086 uses the port address at 4 for LED outputs.
●
Emu8086 enumarates the 12 LEDs as 0,1,2,3,...,A,B.
●
The following is the emulation screen for the LED binking application,
by using the 12 traffic ligths as LEDs.
45
.model small
.data
Part1 Cumle DB 'CIKMAK ICIN BIR TUSA BASINIZ','$'
.code
Basla PROC
.startup
.exit
Basla ENDP
END Basla
47
48
Internal Diagram of
74244 Buffer chip
●
The Buffer chip has 8 inputs (A1-A8), and 8 outputs (Y1-Y8).
●
Each of the G1 and G2 pins controls 4 input bits.
G: Gate enables
49
M / IO
RD
Address
Address A0 (01h)
Lines Decode Input
A1-A15 Logic Enables
5V
Pull-Up
Resistors
8086
Minimum
G: Gate enables
Buttons
G1 G2
Mode
A0
D0 Y0 A1
D1 Y1 A2
74244
D2 Y2 A3
D3 Y3 A4
D4 Y4 (Buffer) A5
D5 Y5 A6
D6 Y6 A7
D7 Y7
Data
Bus 50
Switch Bounce Problem
●
When a switch is closed, it could cause multiple ON and OFF signals lasting
several milliseconds.
●
This multiple switch closing / opening action is called Switch Bounce problem.
(Also called as Contact Noise problem)
●
Software solution: Detect first key-press, wait for a short time, then read again.
●
Hardware solution: Use a Pull-Up or Pull-Down resistor with the switch (or button).
5V Vout
If switch is open, the output is 0V (Low, Logic 0)
If switch is closed, the output is 5V (High, Logic 1)
Switch
is open
51
Switch with
Pull-Up Resistor
●
The pull-up resistor pulls a pin of a chip up to a HIGH state.
●
Input of the buffer chip is normally HIGH.
●
When the switch is closed, input of the chip drops to LOW.
Resistor Input
High
(Buffer)
52
Switch with
Pull-Down Resistor
●
It is the opposite of Pull-Up resistor.
●
The pull-down resistor pulls a pin of a chip down to a LOW state.
●
Input of the buffer chip is normally LOW.
●
When the switch is closed, input of the chip becomes HIGH.
Input
Low
Resistor (Buffer)
53
Switches
8086
CPU 74244
Buffer
Pull-down
resistors
74374
Latch 7 segment
LEDs
55
Example5:
8 LEDs
a) 74245 Buffer as
output interface chip.
Port address
(74245 chip
selection) is
0F000h
56
Determining the Port Address
M/IO Write A15 A14 A13 A12 A11 A10 A9 A8 A7 A6 A5 A4 A3 A2 A1 A0
0 0 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0
0
0 Port address =
0
0 0F000h
0
0
0
0
0
0
0
0
1
1
1
1
0
0
57
Example6:
8 Buttons
+5V
a) 74245 Buffer as
input interface chip.
c) Inputs (8 buttons)
Port address
(74245 chip
selection) is
0F000h
58