Professional Documents
Culture Documents
11-1
Introduction (contd)
65,536 possible I/O ports Data transfer between ports and the processor is over data bus 8088 uses address bus A[15:0] to locate an I/O port AL (or AX) is the processor register that takes input data (or provide output data) Data bus
AL AX 8088
I/O
I/O
I/O
Introduction
I/O devices serve two main purposes
To communicate with outside world To store data
I/O controller acts as an interface between the systems bus and I/O device
Relieves the processor of low-level details Takes care of electrical interface
Introduction (contd)
11-4
Introduction (contd)
To communicate with an I/O device, we need
Access to various registers (data, status,)
This access depends on I/O mapping
Two basic ways Memory-mapped I/O Isolated I/O
11-5
Isolated I/O
Separate I/O address space Separate I/O read and write signals are needed Pentium supports isolated I/O
64 KB address space Can be any combination of 8-, 16- and 32-bit I/O ports Also supports memory-mapped I/O FFFFF Memory addressing space 00000 I/O FFFF I/O addressing 0000 space Memory addressing space
11-6
FFFFF
00000
Direct I/O
Memory-mapped I/O
accumulator,DX
DX gives the port address
; indirect format
ins: port address in DX, memory address in ES:(E)DI outs: port address in DX, memory address in ES:(E)SI We can use rep prefix for block transfer of data
11-7
Accessed through DX
Accessing through DX
IN IN OUT OUT AL, AX, DX, DX, DX DX AL AX
11-8
8088
Input
Address bus
The outputs of the gating device are high impedance when the processor is not accessing the input port When the processor is accessing the input port, the gating device transfers input data to CPU data bus The decoding circuit controls when the gating device has high impedance output and when it transfers input data to data bus
11-9
A7 A6 A5 A4 A3 A2 A1 A0
Data bus
Tri-state buffer CE
Input data
RD IO/M
11-10
11-11
A7 A6 A5 A4 A3 A2 A1 A0
Data bus
Latch CLK
Output data
WR IO/M
11-12
11-13
Vcc R
A3 A2 A1 A0
11-15
11-17
Keyboard scan code and status can be read from port 60H
7-bit scan code is available from
PA0 PA6
An end-notification phase
Programmed I/O Interrupt
Example
Reading a key from the keyboard involves
Waiting for PA7 bit to go low
Indicates that a key is pressed
Reading the key scan code Translating it to the ASCII value Waiting until the key is released
11-20
11-21
D[7:0]
PA[7:0] PB[7:0]
8088
Control port
PC[7:0]
CS
A1 0 1 0 1
A0
Port PA PB PC Control
11-22
11-23
Programming 8255
8255 has three operation modes: mode 0, mode 1, and mode 2
11-24
Programming 8255
Mode 0:
Ports A, B, and C can be individually programmed as input or output ports Port C is divided into two 4-bit ports which are independent from each other
Mode 1:
Ports A and B are programmed as input or output ports Port C is used for handshaking
PA[7:0] STBA IBFA INTRA PB[7:0] PC2 PC1 PC0 PC6, 7 STBB IBFB INTRB PA[7:0] OBFA ACKA INTRA PB[7:0] PC2 PC1 PC0 PC4, 5 OBFB ACKB INTRB
11-25
8255
8255
Programming 8255
Mode 2:
Port A is programmed to be bi-directional
Port C is for handshaking Port B can be either input or output in mode 0 or mode 1 PA[7:0] PC7 PC6 PC4 PC5 PC3 PC0 PC0 PC0 OBFA ACKA STBA IBFA INTRA In In In PB[7:0] Out Out Out STBB IBFB INTRB OBFB ACKB INTRB
8255
1. 2.
Mode 1 Mode 0 Can you design a decoder for an 8255 chip such that its base address is 40H? Write the instructions that set 8255 into mode 0, port A as input, port B as output, PC0-PC3 as input, PC4-PC7 as output ?
11-28
Timing diagram is a combination of the Mode 1 Strobed Input and Mode 1 Strobed Output Timing diagrams.
keyboard
PA0
22H 20H
PA7
PROC NEAR
; read portc ;test IBF ;if IBF=0 ;Read Data
READ
ENDP
11-30
Printer
Data Strobe : to tell the printer to latch the incoming data. Generated Externally
11-31
; check printer ready? IN AL, PORTC ;get OBF TEST AL, BIT1 ;test OBF JZ PRINT ;if OBF=0 buffer is full
PRINT ENDP
11-32
11-33
11-34
Bouncing Problem
11-35
Bouncing
11-36
Software Solution
11-37
De-bouncing Circuitry
Two asynchronous flip-flop solutions are given below
The basic idea is that these flip-flops store the values even if the D/D nodes both float
11-38
Another Solution
11-39
External Interface
Two ways of interfacing I/O devices
Serial
Cheaper Slower
Parallel
Faster Data skew Limited to small distances
11-40
11-41
Synchronous
Sender and receiver must synchronize
Done in hardware using phase locked loops (PLLs)
Expensive
11-42
11-43
11-44
11-45
Data transmission
Modem A alters its computer via Carrier Detect (pin 1) Turns its DCE Ready
Connection termination
11-46
11-48
clk data B0 B1 B2 B3 B4 B5
11-49
Baud (Baud is # of bits transmitted/sec, including start, stop, data and parity).
A7 A6 A5 A4 A3 A2 A1 IO/M
11-50
11-51
Programming 8251
8251 mode register
Mode register
Number of Stop bits 00: 01: 10: 11: invalid 1 bit 1.5 bits 2 bits
Parity enable 0: disable 1: enable Character length 00: 01: 10: 11: 5 bits 6 bits 7 bits 8 bits
Baud Rate 00: Syn. Mode 01: x1 clock 10: x16 clock 11: x64 clock
11-52
Programming 8251
8251 command register
EH
IR
RTS
ER
SBRK
RxE
DTR
TxE
command register
TxE: transmit enable DTR: data terminal ready, DTR pin will be low RxE: receiver enable SBPRK: send break character, TxD pin will be low ER: error reset RTS: request to send, CTS pin will be low IR: internal reset EH: enter hunt mode
11-53
Programming 8251
8251 status register
DSR
SYNDET
FE
OE
PE
status register
transmit ready receiver ready transmitter empty parity error overrun error framing error sync. character detected data set ready
11-54
Write
start
Check RxRDY No
Check TxRDY No
Errors
Parity error: Received data has wrong error -transmission bit flip due to noise. Framing error: Start and stop bits not in their proper places.
This usually results if the receiver is receiving data at the incorrect baud rate.
Overrun error: Data has overrun the internal receiver FIFO buffer.
Software is failing to read the data from the FIFO.
11-56
11-57
8254 Programming
11-58
8254 Programming
Each counter may be programmed with a count of 1 to FFFFH.
Minimum count is 1 all modes except 2 and 3 with minimum count of 2.
Each counter has a program control word used to select the way the counter operates.
If two bytes are programmed, then the first byte (LSB) stops the count, and the second byte (MSB) starts the counter with the new count.
11-59
CNT1
CNT0
RW1
RW0
M2
M1
M0
BCD
NULL COUNT: goes low when the new count written to a counter is actually loaded into the counter
11-60
8254 Modes
11-61
8254 Modes
Mode 2: Counter generates a series of pulses 1 clock pulse wide.
The seperation between pulses is determined by the count. The cycle is repeated until reprogrammed or G pin set to 0.
11-62
8254 Modes
Mode 4: Software triggered one-shot
(G must be 1).
Motor Control
11-64
Motor Control
11-65
11-66
DMA
Direct memory access (DMA)
Problems with programmed I/O
Processor wastes time polling
In our example Waiting for a key to be pressed, Waiting for it to be released
DMA
Frees the processor of the data transfer responsibility
11-67
DMA Example
A hard disk data transfer rate of 5MB/s
One byte every 200 ns !!
DMA
11-69
DMA
DMA is implemented using a DMA controller
DMA controller
Acts as slave to processor Receives instructions from processor Example: Reading from an I/O device
Processor gives details to the DMA controller I/O device number Main memory buffer address Number of bytes to transfer Direction of transfer (memory I/O device, or vice versa)
11-70
DMA
Steps in a DMA operation
Processor initiates the DMA controller
Gives device number, memory buffer pointer,
Called channel initialization
11-72