UNIT - 4 MP&I
UNIT - 4 MP&I
Introduction:
Any application of Microprocessor Based system requires the transfer of data
between external circuitry to the Microprocessor and Microprocessor to the
External circuitry. User can give information (i.e., input) to the Microprocessor
using keyboard and user can see the result or output information from the
Microprocessor with the help of display.
Hence, Interfacing is used to exchange information between two different
applications/devices.
Interface is the path for communication between two components.
Interfacing is of two types –
Memory interfacing and I/O interfacing.
Memory Interfacing:
When we are executing any instruction, we need the microprocessor to access the
memory for reading instruction codes and the data stored in the memory. For this,
both the memory and the microprocessor require some signals to read from and
write to registers. The interfacing process includes some key factors to match with
the memory requirements and microprocessor signals. The interfacing circuit
therefore should be designed in such a way that it matches the memory signal
requirements with the signals of the microprocessor.
IO Interfacing:
There are various communication devices like the keyboard, mouse, printer, etc.
So, we need to interface the keyboard and other devices with the microprocessor
by using latches and buffers. This type of interfacing is known as I/O interfacing.
Block Diagram of Memory and I/O Interfacing:
Output Port:
It is used to send data to the output device such as display from the
microprocessor. The simplest form of output port is a latch. The output device is
connected to the microprocessor through latch as shown in the Fig. 4.29.
When microprocessor wants to send data to the output device, it puts the data on
the data bus and activates the clock signal of the latch, latching the data from the
data bus at the output of latch. It is then available at the output of latch for the
output device.
2. I/O mapped I/O: In I/O mapped I/O, the I/O devices are accessed using
separate I/O ports. This means that the microprocessor needs to use special
instructions to access I/O devices.
Basis for Memory mapped I/O I/O mapped I/O
Comparison
Basic I/O devices are treated as I/O devices are treated as
memory. I/O devices.
Allotted address 16-bit (A0 – A15) 8-bit (A0 – A7)
size
Data transfer Same for memory and I/O Different for memory and
instructions devices. I/O devices.
Cycles involved Memory read and memory I/O read and I/O write
write
Interfacing of Large (around 64K) Comparatively small
I/O ports (around 256)
Control signal No separate control signal is Special control signals are
needed for I/O devices. used for I/O devices.
Efficiency Less Comparatively more
Decoder More decoder hardware Less decoder hardware
hardware required. required.
IO/M’ During memory read or During I/O read and I/O
memory write operations, write operation, IO/M’ is
IO/M’ is kept low. kept high.
Data movement Between registers and ports. Between accumulator and
ports.
Logical Simple Complex
approach
Usability In small systems where In systems that need large
memory requirement is less. memory space.
Speed of Slow Comparatively fast
operation
Example of LDA ****H IN ****H
instruction STA ****H OUT ****H
MOV A, M
Interrupts in 8085:
Whenever more than one I/O device is connected to a microprocessor-based
system, any one of the I/O devices may ask for service at any time. There are two
methods by which the microprocessor can service these I/O devices –
1. Polling Routine and 2. Interrupts
1. Polling Routine:
The Polling routine is a simple program that keeps a check on the occurrences of
interrupts.
The polling routine will first transfer the status of the I/O port to the accumulator
and then checks the content of the accumulator to determine if the service request
bit is set.
If the bit is set then the I/O port service routine is called.
2. Interrupts:
An interrupt is an external asynchronous input that informs the microprocessor to
complete the instruction that is currently executing and fetch a new routine in
order to offer service to the I/O device.
Once the I/O device is serviced, the microprocessor will continue with the
execution of its normal program.
2. Software Interrupts:
In the case of software interrupts, the cause of the interrupt is the execution
of the instruction.
The 8085 microprocessor has eight instructions. These eight instructions
are RST 0 to RST 7.
Such interrupts are called software interrupts.
They allow microprocessors to transfer program control from the main
program to the subroutine program.
After completing the subroutine program. the program control returns back
to the main program.
Hardware Interrupts in 8085:
1. TRAP :
It is a non-maskable, edge and level-triggered interrupt.
It is unaffected by any mask or interrupt enable.
The TRAP signal must make a LOW to HIGH transition and remain HIGH
until acknowledge. This avoids false triggering due to noise or glitches.
It has the highest priority among all interrupts.
This interrupt transfers the microprocessor’s control to location 0024H.
Application: It is used for emergency purposes like power failure, parity
error checker, smoke detector, etc.
2. RST 7.5 :
It is a maskable, edge-triggered interrupt request input line. This interrupt
is triggered at the rising edge of the signal.
It has the highest priority among all maskable interrupts and the second
priority among all interrupts.
The interrupt vector location for this interrupt is 003CH.
3. RST 6.5 and RST 5.5 :
These are level-triggered, maskable interrupt request input lines.
RST 6.5 transfer the microprocessor’s control to location 0034H while
RST 5.5 transfer the microprocessor’s control to location 002CH.
4. INTR :
It is a level triggered, maskable interrupt request input line.
This interrupt works in conjunction with RST N or CALL instruction.
The INTR logic consists of an INTE flip-flop, OR gate, and inverter. The
INTR pin is logically ANDed with the output of the INTE flip-flop.
Software Interrupts in 8085:
The 8085 microprocessor has eight instructions from RST 0 to RST 7.
These instructions allow the transfer of program control from the main
program to predefined service routine addresses.
A predefined service routine is also referred to as ISR.
After completing the ISR program control is transferred back to the main
program.
8085 microprocessor provides eight software interrupts RST 0 to RST 7;
These instructions are used to call interrupt service routine.
Format of RST N Instruction OPCODE is as follows:
6. It has the highest priority among all The priority is lower than that of a
interrupts. software interrupt.
7. It does not affect interrupt control logic. It affects interrupt control logic.
RIM Formate
Bit D7 is status of SID pin on serial port. When RIM instruction is executed
the logic level of SID pin is copied at bit D7.
Bits D6, D5 and D4 are status of pending interrupts.
Bits D3 to D0 are status of interrupt enable flip-flop, mask 7.5, mask 6.5
and mask 5.5. When RIM instruction is executed the status of masking is
loaded at bit D3 to D0.
(1) Data Bus Buffer: It is used to transfer data between the microprocessor and
internal bus.
(2) Read/Write control logic: It sets the direction of the data bus buffer. It controls
all internal read/write operations. It contains initialization and operation
command registers.
(3) Cascaded buffer and comparator: In master mode, it functions as a cascaded
buffer. The cascaded buffer outputs slave identification number on cascade lines.
In slave mode, it functions as a comparator. The comparator reads slave
identification numbers from cascade lines and compares this number with its
internal identification number. In buffered mode, it generates an EN signal.
(4) Control Logic: It generates an INT signal. In response to the INTA signal, it
releases a three-byte CALL address or a one-byte vector number. It controls
read/write control logic, cascade buffer/comparator, in-service register, priority
resolver, and IRR.
(5) Interrupt request register (IRR): It is used to store all pending interrupt
requests. Each bit of this register s set at the rising edge or at the high level of the
corresponding interrupt request line. The microprocessor can read the contents of
this register by issuing appropriate command words.
(6) In-service register (InSR): It is used to store all interrupt levels currently
being serviced. Each bit of this register is set by priority resolver and reset by the
End of the interrupt command word. The microprocessor can read the contents of
this register by issuing appropriate command words.
(7) Priority resolver: It determines the priorities of the bit set in the IRR. To make
a decision, the priority resolver looks at the ISR. If the higher priority bit in the
InSR is set then it ignores the new request. If the priority resolver finds that the
new interrupt has a higher priority than the highest priority interrupts currently
being serviced and the new interrupt is not in service, then it will set the
appropriate bit in the InSR and send the INT signal to the interrupt request.
(8) Interrupt mask register (IMR): It is a programmable register. It is used to
mask unwanted interrupt requests, by writing appropriate command words. The
microprocessor can read the contents of this register without issuing any
command word.
Symbol Description
These are bi-directional 3-bit cascade lines. These lines are used in
CAS0- cascade mode only. In master mode, these lines function as output
CAS2 lines. In this mode, the pIC places a 3-bit slave identification
number on cascade lines.
Operating Modes:
8255A has three different operating modes −
Mode 0 − In this mode, Port A and B is used as two 8-bit ports and Port C
as two 4-bit ports. Each port can be programmed in either input mode or
output mode where outputs are latched and inputs are not latched. Ports do
not have interrupt capability.
Mode 1 − In this mode, Port A and B is used as 8-bit I/O ports. They can
be configured as either input or output ports. Each port uses three lines
from port C as handshake signals. Inputs and outputs are latched.
Mode 2 − In this mode, Port A can be configured as the bidirectional port
and Port B either in Mode 0 or Mode 1. Port A uses five signals from Port
C as handshake signals for data transfer. The remaining three signals from
Port C can be used either as simple I/O or as handshake for port B.
Features of 8255A:
The prominent features of 8255A are as follows −
It consists of 3 8-bit IO ports i.e. PA, PB, and PC.
Address/data bus must be externally demux'd.
It is TTL compatible.
It has improved DC driving capability.
8255 Architecture:
CS A1 A0 Result
0 0 0 PORT A
0 0 1 PORT B
0 1 0 PORT C
0 1 1 Control Register
1 X X No Selection
WR: It stands for write. This control signal enables the write operation. When
this signal goes low, the microprocessor writes into a selected I/O port or control
register.
RESET: This is an active high signal. It clears the control register and sets all
ports in the input mode.
RD: It stands for Read. This control signal enables the Read operation. When the
signal is low, the microprocessor reads the data from the selected I/O port of the
8255.
A0 and A1 : These input signals work with RD, WR, and one of the control signal.
Following is the table showing their various signals with their result.
A1 A0 RD WR CS Result
Input Operation
0 0 0 1 0
PORT A → Data Bus
Output Operation
0 0 1 0 0
Data Bus → PORT A
Terminal Count Register : Fig. 14.64 shows the format of Terminal Count
register.
Note : N is number of bytes to be transferred.
The value loaded into the low order 14 bits (C13 — C0) of the terminal count
register specifies the number of DMA cycles minus one before the terminal count
(TC) output is activated. Therefore, for N number of desired DMA cycles it is
necessary to load the value N-1 into the low order 14-bits of the terminal count
register. The most significant 2 bits of the terminal count register specifies the
type of DMA operation to be performed. It is necessary to load count for DMA
cycles and operational code for valid DMA cycle in the terminal count register
before channel is enabled.
Control logic:
It controls the sequence of operations during all DMA cycles (DMA read, DMA
write, DMA verify) by generating the appiopriate control signals and the 16-bit
address that specifies the memory location to be accessed. It consists of mode set
register and status register. Mode set register is programmed by the CPU to
configure 8257 whereas the status register is read by CPU to check which
channels have reached a terminal count condition and status of update flag.
Mode Set Register:
Fig. 14.65 gives the format of mode set register. Least significant four bits of
mode set register, when set, enable each of the four DMA channels. Most
significant four bits allow four different options for the 8257 Pin Diagram.
It is normally programmed by the CPU after initializing the DMA address
registers and terminal count registers. It is cleared by the RESET input, thus
disabling all options, inhibiting all channels, and preventing bus conflicts on
power-up.
Status Register:
Fig. 14.66 shows the status register format. As said earlier, it indicates which
channels have reached a terminal count condition and includes the update flag
described previously.
The TC status bit, if one, indicates terminal count has been reached for that
channel. TC bit remains set until the status register is read or the 8257 is reset.
The update flag, however, is not affected by a status read operation.
The update flag bit, if one, indicates CPU that 8257 is executing update cycle. In
update cycle 8257 loads parameters in channel 3 to channel 2.
Priority Resolver:
It resolves the peripherals requests. It can be programmed to work in two modes,
either in fixed mode or rotating priority mode.
8253 8254
Reads and writes of the same counter Reads and writes of the same counter
cannot be interleaved. can be interleaved.
Features of 8253/54:
The most prominent features of 8253/54 are as follows −
It has three independent 16-bit down counters.
It can handle inputs from DC to 10 MHz.
These three counters can be programmed for either binary or BCD count.
It is compatible with almost all microprocessors.
8254 has a powerful command called READ BACK command, which
allows the user to check the count value, the programmed mode, the current
mode, and the current status of the counter.
8253/54 Architecture:
1. Dats Bus Buffer:
It is tristate, bidirectional 8-bit data bus buffer.
It is used to interface 8254 data bus with system data bus.
It is internally connected to internal data bus and its outer pins D0-D7 are
connected to system data bus. The direction of data buffer is decided by
read and write control signals.
2. Read/Write Logic:
This block accepts inputs from system control bus and address bus.
In I/O mapped I/O, the signals ‾RD and ‾WR are connected
to ‾IOR and ‾IOW.
In memory mapped I/O ‾RD and ‾WR, are connected
to ‾MEMR and ‾MEMW.
A0 and A1 are directly connected to address lines A0 and A1.
‾CS is connected to address decoder.
The 8254 operation/selection is enables/disabled by ‾CS signal. A0,
A1 selects a specific part ‾WR, ‾RD decides writing data to 8254 or reading
data from 8254.
The control word registers and the counters are selected according to the
signals on line A0 and A1.
A1 A0 Selection
0 0 Counter 0
0 1 Counter 1
1 0 Counter 2
1 1 Control word register
3. Control Word Register:
This register of 8254 programmable interval timer gets selected when A0=1
and A1=1.
It is used to specify the BCD or binary counter to be used, its mode of
operation and the data transfer to be used i.e read or write the data bytes.
If the CPU performs a write operation, the data is stored in the control word
register and is preffered to as control word. It is used to define counter
operation.
The data can only be written into control word register, no read operation
is allowed. Status inforamtion is available with the help of read back
command.
Following table shows the result for various control inputs –
A1 A0 RD WR CS Result
0 0 1 0 0 Write Counter 0
0 1 1 0 0 Write Counter 1
1 0 1 0 0 Write Counter 2
0 0 0 1 0 Read Counter 0
0 1 0 1 0 Read Counter 1
1 0 0 1 0 Read Counter 2
1 1 0 1 0 No operation
X X 1 1 0 No operation
X X X X 1 No operation
4. Counters:
There are three independent, 16-bit down counters.
They can be programmed separately through control word register to
decide mode of counter.
Each counter is having 2 inputs viz. CLK and GATE.
CLK is used as an input to counnter and GATE is used to control the
counter.
The counters give output on OUT pin.
The loaded count value in counter will be decremented by counter at each
clock input pulse. The programmer can read counter without disturbing
counter operation.
Control Word Register Formate of 8254:
The control word register bits, SC1 and SC0, select the control word register
for counter and used to initialize the counters.
A0 and A1 selects counters, but they used to read/load counters by
microprocessor.
The bits RL0 and RL1 are used to read/load, data bytes i.e LSB byte, MSB
byte or both LSB and MSB bytes.
The bits M2, M1 and M0 decides the mode of operation for selected counter,
Mode0- Mode5.
The bit, BCD, decides the mode of counting i.e BCD counter or binary
counter.
This is an active low input signal, used to select the 8254 IC.
Chip
CS If ‾CS = 0 then 8254 will be active and take part in data transfer
Select
from/to 8085 otherwise 8254 will be in de-active state.
Address These are input address lines used to distinguish different parts of
A0 – A 1
Lines 8254 such as counter 0, counter1, counter 2, control word register.
These Lines are active high, output lines. The output is dependent
OUT0-2 Output
on operating modes.