CH 4 Interface
CH 4 Interface
Interfacing
1
Outline of the chapter
2
I/O Instructions
• Two types:
• Transfer data between the processor accumulator (AL, AX, EAX) register and I/O
device: IN and OUT
• - Transfer string data between memory and I/O device directly: INS and OUTS
(for processors above 8086)
• The IN instruction (I/O Read): Inputs data from an external I/O device to the
accumulator.
• The OUT instruction (I/O Write): Copies the contents of the accumulator out to an
external I/O device.
• The accumulator is:
• - AL (for 8-bit I/O),
• - AX (for 16-bit I/O),
• - EAX (for 32-bit I/O).
3
I/O Address
• As with memory, I/O devices have I/O addresses (addresses for the I/O port)
• Up to 64K I/O bytes can be addressed
• The 16-bit port address appears on address bus bits A15-A0
This allows I/O devices at addresses 0000H-FFFFH
• Two ways to specify an I/O port address:
• An 8-bit immediate (fixed) address (specified as a byte in the instruction):
• e.g. IN AX, p8 ; Reads a word from port p8
• 0000H-00FFH (can only see the first 256 addresses)
• A 16-bit address located in register DX (can be easily varied):
• e.g. OUT DX, AL; outputs the byte in AL to the port whose address is in DX
• 0000H-FFFFH (upto 16 bit addresses). i.e. high port addresses are
DX
• accessible only through DX addressing 00FF
Immediate
4
I/O Data widths
•As with memory, I/O ports are also organized as bytes
•A port can be 1, 2, or 4 bytes wide (not 8 bytes wide on the
Pentium)
00F2H E
A Port is 2 bytes wide
00F1H X
AX Port is 1 byte wide
A
Port Address p8 00F0H LS byte L 5
INS and OUTS I/O instructions
• They address I/O port using register DX
• Data width of transfer specified by using INSB, INSW, and INSD for byte, word, and
double word
• Can be prefixed with REP to repeat the instruction for a number of times stored in CX
6
(Note corrections)
a d
Re
I/O
DX
r i t e
W
I/O
7
Isolated vs. Memory Mapped
• I/O can be either:
• Isolated I/O: uses the dedicated I/O instructions (IN, OUT and INS, OUTS) and has its own
address space for I/O ports (0000H-FFFFH)- isolated from the memory address space
• Memory mapped I/O: uses memory reference instructions , e.g. MOV, and a region of the
memory address map. So address space is shared between memory and I/O
• But most Intel-based systems e.g. the PC, use isolated I/O
• Some other processors do not have dedicated I/O instructions and therefore use only
memory-mapped I/O addressing, e.g. the PowerPC microprocessor (Macintosh computers)
8
Basic Input/ Output Interfacing
9
Memory and I/O address
Maps for the 8086/8088
Memory: I/O Port specified
in DX, either explicitly or implicitly
MOV
MOV
10
IN (I/O Read)
• The IN instruction primarily takes the following forms:
Data from the Input port addressed
is put on the data bus for the processor to read
• into the A register
• IN AL,23H ;immediate
• IN AL,DX ;DX holds address
• IN AX,44H
• IN AX,DX
• IN EAX,2AH
• IN EAX,DX
13
Basic 8-bit Input Interface:
Reads the status of 8 toggle
Switches (a byte read)
Pull-up
Resistors To μP
Gate
Outputs:
0 1 Normally Hi-Z
Toggle switches Unless device is
Selected
3-state buffer (both G1 and G2 low)
The SEL signal is generated (active low)
By decoding: Circuit can be expanded for
- The address for the I/O port 16-bit (word) or 32-bit (DWord)
- The I/O READ operation interfaces 14
Basic Output Port (for I/O Writes)
• The basic output port writes data from the mP data bus to an output port whenever the mP
executes the correct OUT instruction with the correct I/O port address
• Must latch the processor data put on the bus during the I/O instruction to make it
• No need for 3-state (Tri-State) buffers as the data bus is at the input side of the latch
15
Basic 8-bit Output Interface:
Controls 8 LEDs (1: OFF, 0: ON)
From μP
Edge-triggered
latch
OE
No HiZ. Data is latched and remains here until the next OUT
O/P always
instruction to this port is executed
enabled
The SEL is generated (for + ive edge triggering) by decoding:
- The address for the I/O port
- The I/O WRITE operation 16
Parallel Port
• The parallel port is an example of interfacing slow devices, e.g. a printer, to the processor
• A printer can print say 100’s of characters per sec (CPS), but the processor can output as
many as 1000’s of CPS
• To achieve ‘flow control’ and proper operation we use a technique called handshaking
• Handshaking regulates the flow of data from the processor to a slower peripheral device
to ensure correct operation
17
Interfacing
When connecting external input and output devices to the processor, we must take into account the
DC characteristics and drive capabilities of the mP pins.
(Fan-out considerations
For outputs before)
μP Input μP Output
Source Sink
Sink Source
18
Port Address Decoders
• As with memory addresses, port addresses must also be decoded to select an I/O device for a
particular port number.
• Will consider here only isolated I/O (using dedicated instructions: IN, OUT, etc.)
• - i.e. Only the least significant eight address bits A7-A0 are decoded. Limits number of I/O
ports to 256 (enough)
• - All 16-bits of the I/O address A15-A0 are decoded, allowing the use of up to 64K ports
• Isolated I/O transfers are activated using (depending on processor and mode):
20
BUS
BUFFERING
AND
LATCHING
21
BUS
BUFFERING
AND
LATCHING
22
❑ Basic Bus Operation
• The three buses of 8086/8088 function the same way as any other microprocessor.
• If data are written to memory the processor:
• outputs the memory address on the address bus
• outputs the data to be written on the data bus
• issues a write (WR) to memory
• and IO/M= 0 for 8088 and IO/M = 1 for 8086
• Strobe Width
• The other timing factor to affect memory operation is the width of the RD strobe.
• The time for this strobe at a 5 MHz clock rate is 325 ns.
• This is wide enough for almost all memory devices manufactured with an access
time of 400 ns or less.
23
Chapter Four: Interfacing
Programmable Peripheral Interface (8255A)
24
Outline of the topic
✔ Pin diagram
✔ Block diagram
✔ Interfacing the 8255
✔ Programming the 8255
• Mode 0
• Mode 1
• Mode 2
25
Programmable Peripheral Interface (8255)
26
Programmable Peripheral Interface (8255)
❑ Pin diagram:
27
Programmable Peripheral Interface (8255)
❑ Block diagram:
28
29
Programmable Peripheral Interface (8255)
❑ Block diagram:
• Data Bus Buffer
• This tri-state bidirectional buffer is used to interface the internal data bus of 8255 to
the system data bus.
• Input or Output instructions executed 'by the CPU either Read data from, or Write data
into the buffer.
• Output data from the CPU to the ports or control register, and input data to the CPU
from the ports or status register are all passed through the buffer.
30
Programmable Peripheral Interface (8255)
❑ Block diagram:
• Control Logic
• The control logic block accepts control bus signals as well as inputs from the address
bus, and issues commands to the individual group control blocks (Group A control
and Group B control).
31
Programmable Peripheral Interface (8255)
❑ Block diagram:
• Group A and Group B Controls
• Each of the Group A and Group B control blocks receives control words from the
CPU and issues appropriate commands to the ports associated with it.
• The Group A control block controls Port A and PC7-PC4 while the Group B control
block controls Port B and PC3-PC0.
32
Programmable Peripheral Interface (8255)
❑ Block diagram:
• Group A and Group B Controls
• Port A: This has an 8-bit latched and buffered output and an 8-bit input latch. It can be
programmed in three modes: mode 0, mode 1 and mode 2.
• Port B: This has an 8-bit data I/O latch/ buffer and an 8-bit data input buffer. It can be
programmed in mode 0 and mode 1.
• Port C: This has one 8-bit unlatched input buffer and an 8-bit output latch/buffer. Port C can
be split into two parts and each can be used as control signals for ports A and B in the
handshake mode. It can be programmed for bit set/reset operation.
33
Programmable Peripheral Interface (8255)
34
Programmable Peripheral Interface (8255)
35
Programmable Peripheral Interface (8255)
❑ Interfacing the 8255
✔ When the address bus contains one of these four port addresses during an I/O access, (CS) ̅ will
be pulled low. The 8255 will internally decode the states of A0 and A1 and determine which
port to access.
✔ In this example, port A has port address A0H, Ports B and C are accessed through ports A1H
and A2H, respectively, and the control port is at A3H.
✔ The nicest feature of the 8255 is that different hardware circuits can be connected to ports A, B,
and C, with the direction (input or output) of each port configured with initial programming.
✔ This allows an 8088/86-based system with an 8255 in it to be used for many different purposes.
36
Programmable Peripheral Interface (8255)
37
Programmable Peripheral Interface (8255)
38
Programmable Peripheral Interface (8255)
Example 4-5: Find the control(mode) word if PA=out, PB=in, PC0-PC3=in and PC4-PC7=out.
And program the 8255 to get data from port B and send it to port A.
In addition, data from PCL is sent out to the PCU
Use port addresses of 300H-303H for the 8255 chip
39
Programmable Peripheral Interface (8255)
40
Programmable Peripheral Interface (8255)
41
Programmable Peripheral Interface (8255)
42
Programmable Peripheral Interface (8255)
43
Programmable Peripheral Interface (8255)
44
Programmable Peripheral Interface (8255)
❑ Mode 1 Operation:
✔ Port B operates in the same way, using PC2 and PC1 as handshaking signals.
✔ Both ports have the capability of causing an interrupt when data is strobed into them.
✔ The INTR output will go high when IBF goes high and the internal interrupt-enable bit
is set.
✔ PC4 and PC2 make up the interrupt-enable bits for ports A and B. Setting PC4 will
cause INTRa to go high when data is strobed into port A.
✔ Reading the input port will clear the interrupt request. This interrupt mechanism is a
useful alternative to using software to constantly poll the input port.
45
Programmable Peripheral Interface (8255)
46
Programmable Peripheral Interface (8255)
❑ Mode 1 Operation:
47
Programmable Peripheral Interface (8255)
48
Programmable Peripheral Interface (8255)
❑ Mode2 Operation
❑ Reading Assignment
49
Programmable Peripheral Interface (8255)
50
Programmable Peripheral Interface (8255)
✔ In this mode, individual bits of port C can be used for applications such as an
On/Off switch.
✔ The BSR word can also be used for enabling or disabling interrupt signals
generated by Port C when the 8255 is programmed for Mode 1 or 2 operation.
51
Programmable Peripheral Interface (8255)
52
Programmable Peripheral Interface (8255)
53
54
•Applied Control Systems
• Stepper Motors
55