Professional Documents
Culture Documents
CHAPTER
Interfacing Fundamentals
3.1 Introduction
There is no doubt that the microcomputer revolution will continue into the
future and many will be required to specify and integrate microprocessors into
products or systems in their own disciplines. Therefore, well-designed flexible
interfaces will be required to ensure compatibility with other equipments and to
extend design options.
Interfaces are the last items to be seriously considered in the race of new
technology, and it deals with the systematic study of microprocessor interfaces
and their applications in many diversified fields. In this subject students learn
how to interface microprocessors, and hence microcomputers and other related
equipments, to external digital or analog devices.
The microprocessor progress has advanced at a pace perhaps unparallel in
scientific history. Since the introduction of the first microcomputer chip in 1971,
there have been four generations of microprocessors, and the number of devices
per chip has increased by a factor of 2000, the clock frequency by a factor of 1000,
and the overall throughput of the microprocessor has increased by hundred or
several hundreds of magnitudes.
Developing a microprocessor (P)-based system represents one of the most
difficult tasks that can confront an engineer. Advances in microprocessor
architectures and capabilities are forcing changes in development systems and
the ways in which they develop microcode instructions. Also, all P architectures
are not created equal when it comes to providing designers with the tools they
need for effective systems resource management. Therefore, well designed
Page 105
Interface
Signals
Interfacing
Device
(ID 1)
Interface
Signals
Interfacing
Device
(ID 2)
Page 106
Page 107
data transfer schemes have been developed to solve the interfacing problems
with I/O devices.
The data transfer schemes have been broadly classified into the following two
categories.
1. Programmed data transfer.
2. Direct memory access data transfer.
In programmed data transfer, a memory resident routine (subroutine) requests
the device for data transfer to or from one of the processor register.
Programmed data transfer scheme is used when a relatively small amount data
are to be transferred. In these schemes, usually one byte or word of data is
transferred at a time. Examples of devices using parallel data transfer are
ADC,DAC, Hex-keyboard, 7-segment LED's, etc.
The programmed data transfer scheme can be further classified into the
following three types.
1. Synchronous data transfer scheme.
2. Asynchronous data transfer scheme.
3. Interrupt driven data transfer scheme.
In DMA data transfer, the processor is forced to hold state by an I/O device until
the data transfer between the device and the memory is completed.
The processor does not execute any instructions during the hold period. The
DMA data transfer is used for large block of data transfer between I/O device
and memory. Typical examples of devices using DMA are CRT controller, floppy
disk, hard disk, high speed line printer, etc.
The different types of DMA data transfer schemes are
1. Cycle stealing DMA.
2. Block or Burst mode DMA.
3. Demand transfer mode DMA.
The fig below shows the various types of data transfer schemes.
Page 108
Page 109
Data transfers between the microprocessor and the peripherals are primarily
asynchronous.
Program controlled data transfers can take place under several conditions. They
are:Unconditional: The microprocessor assumes that a peripheral is always
available. For example, to display data at an LED port,. The microprocessor
simply enables the port, transfers data and goes on to execute the next
instruction.
Polling: The microprocessor is kept in a loop to check whether data are available.
The KYCLO loop in the matrix keyboard program is an example of polling the
input device for data availability.
Interrupt: The microprocessor is interrupted from its normal execution of
program by an I/O device, when the latter is ready. Then the microprocessor
suspends execution of the program, & branches to service the interrupt. After
completing the I/O transfer, the microprocessor returns to the main program
and continues. This scheme eliminates the need for the microprocessor to wait in
a loop until the device gets ready and hence is more efficient.
With ready signal: When peripheral response time is slower than the
microprocessor execution time, READY signal is used. The microprocessor
samples this signal during T2 of every Read/ writes machine cycle. If it is high,
The I/O device is ready and the microprocessor goes ahead with transfer. If
READY is low, it means that the peripheral is not ready and additional T states
will be inserted in the, execution cycle by external hardware. These T -states are
called WAIT states. They prolong the instruction execution; this scheme is
generally used with slow memory devices.
With handshake Signals: Handshake signals are signals exchanged prior to data
transfer. Their purpose is ensure readiness of the peripheral and to synchronize
timing of data transfer For example the IBF, STB, OBF signals in mode 1
operation of 8255 - A are handshake signals. These are called STATUS CHECK
Compiled by : Dr.. Manoj V.N.V.
Page 110
Page 111
Scheme
Interrupt driven data transfer scheme
The interrupt driven data transfer scheme is the best method of data f transfer for
effectively utilizing the processor time. In this scheme, the processor first initiates
the I/O device for data transfer. After initiating the device, the processor will
continue the execution of instructions in the program. Also at the end of an
instruction the processor will check for a valid interrupt signal. If there is no
interrupt then the processor will continue the execution.
When the IO device is ready, it will interrupt the processor. On receiving an
interrupt sigt1al the processor will complete the current instruction execution
and saves the processor status in stack. Then the processor call an interrupt
service routine (ISR) to service the interrupted device. At the end of ISR the
processor status is retrieved from stack and the processor starts executing its
main program. The sequence of operations for an interrupt driven data transfer
scheme is shown in the figure below.
Page 112
Sequence
In polled and status check I/O, the microprocessor is kept in a loop to check for
data availability at the I/O Port. This scheme is inefficient because the
microprocessor is unnecessarily tied up in a loop. Instead, it is more efficient to
let the microprocessor carry on with its main job of executing programs without
having concern for the I/O device readiness, and let the I/O device send a signal
o the microprocessor as and when it gets ready. Such a signal is called an
INTERRUI signal.
On receiving the interrupt signal, the microprocessor takes the following
sequence of steps to process the requirement of the VO device, which sent the
signal.
The microprocessor P acknowledges the receipt of interrupt
signal.
The microprocessor completes execution of the current
instruction.
Compiled by : Dr.. Manoj V.N.V.
Page 113
Page 114
Page 115
Page 116
upon execution of input or output instructions by the CPU. Control words and
status information are also transferred through the data bus buffer. Read/Write
and Control Logic The function of this block is to manage all of the internal and
external transfers of both Data and Control or Status words. It accepts inputs
from the CPU Address and Control busses and in turn, issues commands to both
of the Control Groups.
Group A and Group B Controls
The functional configuration of each port is programmed by the systems
software. In essence, the CPU outputs a control word to the 8255A. The control
word contains information such as mode, bit set, bit reset, etc., that
initializes the functional configuration of the 8255A.
Each of the Control blocks (Group A and Group B) accepts ``commands''
from the Read/Write Control Logic, receives ``control words'' from the internal
data bus and issues the proper commands to its associated ports.
Control Group A - Port A and Port C upper (C7-C4)
Control Group B - Port B and Port C lower (C3-C0)
The control word register can be both written and read as shown in the
address decode table in the pin descriptions. Figure 6 shows the control word
format for both Read and Write operations. When the control word is read, bit
D7 will always be a logic ``1'', as this implies control word mode information.
Ports A, B, and C
The 8255A contains three 8-bit ports (A, B, and C). All can be configured
in a wide variety of functional characteristics by the system software but each
has its own special features or personality to further enhances the power and
flexibility of the 8255A.
Port A: One 8-bit data output latch/buffer and one 8-bit input latch buffer.
Port B: One 8-bit data input/output latch/buffer.
Port C: One 8-bit data output latch/buffer and one 8-bit data input buffer (no
latch for input). This port can be divided into two 4-bit ports under the mode
Compiled by : Dr.. Manoj V.N.V.
Page 117
control. Each 4-bit port contains a 4-bit latch and it can be used for the control
signal outputs and status signal inputs in conjunction with ports A and B.
8255A OPERATIONAL DESCRIPTION
Mode Selection
There are three basic modes of operation that can be selected by the system
software:
Mode 0 Basic input/output
Mode 1 Strobed Input/output
Mode 2 Bi-directional Bus
When the reset input goes ``high'' all ports will be set to the input mode with all
24 port lines held at a logic ``one'' level by the internal bus hold devices. After the
reset is removed the 8255A can remain in the input mode with no additional
initialization required.
During the execution of the system program, any of the other modes may
be selected by using a single output instruction. This allows a single 8255A to
service a variety of peripheral devices with a simple software maintenance
routine.
The modes for Port A and Port B can be separately defined, while Port C is
divided into two portions as required by the Port A and Port B definitions. All of
the output registers, including the status flip-flops, will be reset whenever the
mode is changed. Modes may be combined so that their functional definition can
be ``tailored'' to almost any I/O structure. For instance; Group B can be
programmed in Mode 0 to monitor simple switch closings or display
computational results, Group A could be programmed in Mode 1 to monitor a
keyboard or tape reader on an interrupt-driven basis.
The mode definitions and possible mode combinations may seem
confusing at first but after a cursory review of the complete device operation a
simple, logical I/O approach will surface. The design of the 8255A has taken into
account things such as efficient PC board layout, control signal definition vs PC
Compiled by : Dr.. Manoj V.N.V.
Page 118
Page 119
Page 120
0 0
0 0
0 1 1
=> (83)H.
Page 121
0
0
0
0
X
X
X
X
X
X
X
X
X
X
X
X
1 1 1 1
0 1 1 1
1 1 1 0
0 1 1 0
(OF)H
(O7)H
(OE)H
(06)H
Page 122
Each port uses three bits from port C as handshake signals. The remaining
two bits from port C can be used for simple I/O.
Page 123
Mode 1 Input
Configuration
STB (Strobe Input): This is-an active low signal, generated by the input device,
when a byte of data is transmitted. On receipt of this signal, the 8255 generates
two signals, IBF and INTR. IBF is routed to the input device and INTR to the
microprocessor.
IBF (Input Buffer Full): This is an active high signal. It tells the peripheral device
that the previous byte sent by the device is there in the buffer and the
microprocessor is yet to read the same. This kind of acknowledgement and
information enables the peripheral t<> defer sending the next data byte until the
buffer is empty, which is indicated by IBF going low:
INTR (Interrupt Request): This is an output signal generated by 8255 in response
to IBF, 8TB and INTE (Interrupt enable). This is used to interrupt the
microprocessor to read the data byte from the buffer.
Page 124
INTE: It is an internal flip-flop for enabling or disabling INTR signal. The two
flip-flops INTEA and INTEB are set/reset by using the BSR mode.
MODE 1 Control word and status-words: To configure port A and port B as
input ports, the mode 1 control word is as follows.
The status word is constituted by port C bits. When the microprocessor reads
port C, the status word is placed in accumulator. Then the microprocessor can
examine the bits to determine the status. The status word is shown below.
Page 125
OBF: (Output Buffer Full) -This is an active low signal generated by 8255A to
indicate to the peripheral that the microprocessor has written one byte of data
into the output port and that it is ready to be read by the device from the port.
ACK: (Acknowledge): This is an input signal from the peripheral to 8255,
indicating that it has received the byte from the port. It is active low.
INTR: (Interrupt Request) - This is an output signal generated by 8255. It is set by
OBF, ACK and 1NTE. It can be used to interrupt the MPU for the next data byte.
INTE: (Interrupt Enable): This is an internal flip-flop to enable interrupts. The
two flip-flows INTEA and INTEB are controlled by the bits PC6 and PC2
respectively through BSR mode.
PC4, PC5: These two lines can be setup either as input or output.
Page 126
=>(FC)H PortA
=>(FD)H Port B
=>(FE)H Port C
=>(FF)H CONTL REG.
We find from the circuit diagram that Port A is configured as input port for
keyboard in mode 1 and that Port B is configured as output Port for printer in
mode 1. Looking at the handshake signals, we observe that, the keyboard is
interfaced for Interrupt I/O and the printer is interfaced for status check I/O.
To write initialization instruction, we need to determine .The control word to set
up C port A for input and Port B for output in mode 1.
The BSR control word to set lNTEA. The status word to check OBFB line.
B
Page 127
0 1 1 x 1 0 x = B4H
2. BSR Control word to set INTEA: INTEA is controlled by PC4. To set PC4, the
control word in BSR mode is:
D7 D6 D5 D4 D3 D2 D1 D0
0 X X X 1 0 0 x = 09H
3. Status Word to Check OBFB: OBFB is indicated by PC1. Therefore, the masking
B
Page 128
Another
Standard
Stepper
Motors Excitation Sequence
PA3 PA2 PA1 PA0
HEX
0
06
05
09
0A
Table: Shows two standard excitation sequences for stepper motors. The second
one is followed for our discussions.
A typical stepper motor control system is shown in fig. This is 2-phase
four winding stepper motor. The system consists of 8085 microprocessor as CPU,
EPROM and RAM memory for program and data storage for stack. Using Intel
8279, a keyboard and six numbers of 7-segment LED displays have been
interfaced in the system. Though the keyboard operator can issue commands to
control the system. The LED displays have been provided to display messages to
the operator.
The windings of stepper motor are connected to the collector of
Darlington pair transistor. The transistors are switched ON (OFF by the
microprocessor through the ports of 8255 and buffer (74LS245). A free wheeling
diode is connected across each winding for fast switching. The processor has to
out put a switching sequence and wait for the 1 to 5 mille seconds before sending
the next switching sequence.
A typical stepper motor control system is shown in fig below. The
system consists of 8085 microprocessor as CPU, EPROM and RAM memory for
program & data storage and for stack. Using INTEL 8279, a keyboard and six
number of 7-segment LED display has been interfaced in the system. Through
the keyboard the operator can issue commands to control the system. The LED
display has been provided to display messages to the operator.
Page 129
Page 130
Page 131
schedule we can conclude those three different delay routines is sufficient for
implementing the twelve switching schedules.
Page 132
Fig: Relay connection to each of the 230 V Lights ( Traffic Control System)
Page 133
The system has been designed to accept the desired temperature and
various control commands through the keyboard. The 7-segment display has
been provided to display the temperature of the boiler at any time.
The temperature of the body is measured using a temperature sensor that
can be used for temperature measurements are Thermo-couples, Thermistors ,
PN junctions, IC sensors like AD 590. These sensors will convert the input
temperature to proportional analog voltage or current. The output signal of the
sensor will be a weak signal and so it has to be amplified using high input
impedance op-amp. Then the analog signal is scaled to suitable level by the
signal conditioning circuit.
The microprocessor can process only digital signals and so the analog
signal from signal conditioning circuit cannot read by the processor directly. The
system has an analog-to-digital converter (ADC) to convert the analog signal to
proportional digital data. In this system the ADC is interfaced to 8085
microprocessor through port-A of 8255. The 8085 processor send signal to ADC
to start conversion and at the end 0 conversion it read the digital data from the
port-A of 8255. The 8085 processor calculates the actual temperature using the
input data and displays it on the 7-segment LED. Also, the processor compares
the desired temperature with actual temperature (the operator can enter the
desired temperature through the keyboard) and calculate the error that is the
difference between actual temperature and desired temperature.
Page 134
Page 135
stripping off the framing bits, converting the serial data bits back into bus form,
and checking blocks of data for accuracy. The heart of the serial port is a single
ICthe Universal Synchronous Asynchronous Receiver/Transmitter (USART). The
UART connects directly to the PC bus architectureeither added to the
motherboard or incorporated on an expansion board. A UART IC contains all of
the internal circuitry necessary to process, transmit, and receive data between the
serial line and the PC bus.
Page 136
IBM and compatible PCs implement a serial port as either a 25-pin or 9-pin subminiature D-type connector (Fig. 40-3). Both ends of the serial cable are identical.
Be concerned with three types of signals in a serial connection: data lines, control
(or handshaking) lines, and ground lines. Table 40-3 identifies the name and
description of each conductor for both 25-pin and 9-pin serial connections.
Remember that all data and control signals on the serial port are bi-polar.
Page 137
line is asserted, the DTE waits for the CTS (Clear to Send) signal back from the
DCE. Once the DTE receives a valid CTS signal, it can begin transferring data.
This RTS/CTS handshake forms the basis for data flow control.
DTR AND DSR
When the DTE is turned on or initialized and ready to begin serial operation, the
DTR (Data Terminal Ready) line is asserted. This tells the DCE (i.e., modem) that
the DTE (i.e., computer) is ready to establish a connection. When the DCE has
initialized and is ready for a connection, it will assert the DSR (Data Set Ready)
line back to the DTE. Once the DTE is ready and recognizes the DSR signal, a
connection is established. This DTR/DSR handshake is established only once
when the DTE and DCE devices are first initialized, and it must remain active
throughout the connection. If either the DTR or DSR signal should fall, the
communication channel will be interrupted (and the RTS/CTS handshake will
no longer have any effect).
DCD
The DCD (Data Carrier Detect) signal is particularly useful with modems. It is
produced by the DCE when a carrier is detected from a remote target, and the
DCE is ready to establish
a communications pathway. The DCD signal is then sent back to the DTE. Once
the DCD line is asserted, it will remain so as long as a connection is established.
RI
The RI (Ring Indicator) signal is asserted by the DCE, and is also particularly
useful with modems. It is produced by the DCE when a telephone ring is
detected. This becomes a vital signal if it is necessary for a remote user to call in
and access your computer (i.e., a BBS configuration).
8251-Progammable Communication Interface
The 8251 A is a programmable chip designed for synchronous and asynchronous
serial data communication, packaged in .a 28-pin DIP. The 8251A is the enhanced
version of its predecessor, the 8251. and is compatible with the 8251. Figure 16.12
Page 138
shows the block diagram of the 8251A. It includes five sections: Read/Write
Control Logic, Transmitter, Receiver, Data Bus Buffer, and Modem Control.
The control logic interfaces the chip with the MPU, determines the functions of
the chip according to the control word in its register (to be explained below), and
monitors the data flow. The transmitter section converts a parallel word received
from the MPU into serial bits and transmits them over the TxD line to a
peripheral. The receiver section receives serial bits from a peripheral, converts
them into a parallel word, and transfers the word to the MPU. The modem
control is used to establish data communication through modems over telephone
lines.
Page 139
Page 140
RD-Read: When this signal goes low, the MPU either reads a status from the
status register or accepts (inputs) data from the data buffer. This is connected to
either IOR or MEMR.
RESET -Reset: A high on this input resets the 8251A and forces it into the idle
mode.
CLK-Clock: This is the clock input, usually connected to the system clock. This
clock does not control either the transmission or the reception rate. The clock is
necessary for communication with the microprocessor.
Control Register This 16-bit register for a control word consists of two
independent bytes: the first byte is called the mode instruction (word) and the
second byte is called command instruction (word). This register can be accessed
as an output port when the C/D pin is high.
Status Register This input register checks the ready status of a peripheral. This
register is addressed as an input port when the C/D pin is high; it has the same
port address as the control register. Data Buffer This bidirectional register can be
addressed as an input port and an output port when the CID pin is low. Table
16.4 summarizes all the interfacing and control signals.
TRASMITTER SECTION
Page 141
The transmitter accepts parallel data from the MPU and converts them into serial
data. It has two registers: a buffer register to hold eight bits and an output
register to convert eight bits into a stream of serial bits. The MPU writes a byte in
the buffer register;
whenever the output register is empty the contents of the buffer register are
transferred to the output register. This section transmits data on the TxD pin
with the appropriate framing bits (Start and Stop). Three output signals and one
input signal are associated with the transmitter section.
Page 142
Page 143
accepts the following bits, forms a character, and loads it into the buffer register.
Subsequently, the parallel byte is transferred to the MPU when requested. In the
asynchronous mode, two input signals and one output signal are necessary, as
described below.
RxD-Receive Data: Bits are received serially on this line and converted into a
parallel byte in the receiver input register.
RXC-Receiver Clock: This is a clock signal that controls the rate at which bits are
received by the USART. In the asynchronous mode, the clock can be set to I, 16,
or 64 times the baud.
RxRDY -Receiver Ready: This is an output signal. It goes high when the USART
has a character in the buffer register and is ready to transfer it to the MPU. This
line can be used either to indicate the status or to interrupt the MPU.
INITIALIZING THE 8251A
Page 144
To implement serial communication, the MPU must inform the 8251A of all
details, such as mode, baud, Stop bits, parity, etc. Therefore, prior to data
transfer, a set of control words must be loaded into the 16-bit control register of
the 8251A. In addition, the MPU must check the readiness of a peripheral by
reading the status register. The control words are divided into two formats:
mode words and command words. The mode word specifies the general
characteristics of operation (such as baud, parity, number of Stop bits), the
command word enables data transmission and/or reception, and the status word
provides the information concerning register status and transmission errors.
Page 145
No parity check
Page 146
4. Write instructions to initialize the 8251A to read the status word, and set up a
loop until the transmitter (TxRDY) is ready.
PORT ADDRESS
a. The Chip Select line of the 8251A is enabled when the address lines A7
through Al are at logic 1. To select the control register or the status register, the
cif5 line should be high, which means that address line Ao should be 1.
Therefore, the port address of the control register and the status register = FFH.
The control register is an output port and the status register is an input port; they
are identified by WR and RD signals, even if their port addresses are the same.
b. The data register is selected when the cif5 line goes low; thus, Ao should be
low. The port address of the data register = FEH. The register i~ bidirectional,
and the same address is used to receive or transmit data. The input and output
functions are identified by RD and WR signals.
2. RS-232C Signals, LINE DRIVERS, AND LINE RECEIVERS
Figure shows that three RS-232 signals- TxD, RxD, and Ground-are being used
for serial communication between the CRT terminal and the 8085 system. The
terminal transmits data on pin 2 and receives on pin 3; on the other hand, the
8085 system receives on pin 2 and transmits on pin 3 using the 8251A. Therefore,
the terminal is connected as the DTE and the system plays the role of the DCE;
the 8251A is part of the 8085 system.
Data transmitted over the TxD line (pin 19 of the 8251A) are at the 1TL logic
level. These bits are converted to RS-232 voltage levels and negative logic by line
driver MC 1488. Data received by the 8251A over the RxD line (pin 3) should be
at the 1TL logic level. Therefore, the RS-232 signals at pin 2 of the connector are
converted to the positive logic level by line receiver MC 1489. The line driver and
receiver are described here briefly.
Line Driver: MC 1488. This is a quad line driver that converts TTL input levels to
a maximum + 15 Voc output signal. Typically, it is used with t 12 V power
supply. For logic 0 input (< 0.8 VDC) the output is around + 10 V, and for logic I
Compiled by : Dr.. Manoj V.N.V.
Page 147
input ( > +2.4 VDC) the output is around -10 V; thus, the positive true logic is
converted into negative true logic for RS-232C signals. The internal circuit of the
MC 1488 functions much like a comparator. For an input lower than the
threshold voltage, the output approaches positive power supply voltage, and for
an input higher than the threshold voltage, the output approaches negative
power supply voltage.
Line Receiver: MC 1489 this is a quad line receiver that converts high voltage
signals (+ 15 V) into TTL logic levels. Output voltages usually range from 0.2 V
(low) to 4.0 V (high). The internal circuit functions as an on/off transistor. When
the transistor base has a negative input voltage, the transistor is turned off and
the collector voltage (the output of the MC 1489) is high. When the transistor
base has a positive input voltage, the transistor is driven into saturation to 0.2 V.
TIALIZATION
The control words necessary for the given specifications are as follows:
Mode Word = CAH
Stop Bits Parity Character = 153.6 k/16
Command Word = 11H
Status Word = 01H
Page 148
Block diagram
I'll examine the block diagram and next we'll explore the internal registers and
operating modes of this device. Take note, the timer has three independent,
programmable counters and they are all identical.
Six programmable timer modes allow the 82C54 / 8253 to be used as an event
counter, elapsed time indicator, programmable one-shot, and in many other
applications.
The block labeled data bus buffer contains the logic to buffer the data bus to /
from the microprocessor, and to the internal registers. The block labeled read /
write logic controls the reading and the writing of the counter registers. The final
block, the control word register, contains the programmed information that is
sent to the device from the microprocessor. In effect this register defines how the
8253 logically works. Each counter in the block diagram has 3 logical lines
connected to it. Two of these lines, clock and gate, are inputs. The third, labeled
OUT is an output. The function of these lines changes and depends on how the
device is initialized or programmed.
Page 149
PIN configuration
The following picture shows the pin configuration of the 8253 and a general
definition of the lines follows:
Clock This is the clock input for the counter. The counter is 16 bits. The
maximum clock frequency is 1 / 380 nanoseconds or 2.6 megahertz. The
minimum clock frequency is DC or static operation.
Out This single output line is the signal that is the final programmed output of
the device. Actual operation of the out line depends on how the device has been
programmed.
Gate This input can act as a gate for the clock input line, or it can act as a start
pulse, depending on the programmed mode of the counter.
Signal
Status
Mode
0
Rising
Disables counting
--
--
1) Disables counting
2) Sets output
immediately high
1) Disables counting
2) Sets output
immediately high
Disables counting
1) Initiates
counting
2) Resets output
after next clock
1) Reloads
counter
2) Initiates
counting
Initiates counting
--
-Initiates counting
High
Enables
counting
--
Enables
counting
Enables
counting
Enables
counting
--
Page 150
COUNTER 1
COUNTER 2
MODE
WORD
or
RD
WR
A0
A1
function
Load counter 0
Read counter 0
Load counter 1
Read counter 1
Load counter 2
Read counter 2
Write
CONTROL WORD
- -
mode
word
0
No-operation
Counter #0, #1, #2 Each counter is identical, and each consists of a 16-bit, presettable, down counter. Each is fully independent and can be easily read by the
CPU. When the counter is read, the data within the counter will not be disturbed.
This allows the system or your own program to monitor the counter's value at
any time, without disrupting the overall function of the 8253.
Control Word Register This internal register is used to write information to, prior
to using the device. This register is addressed when A0 and A1 inputs are logical
1's. The data in the register controls the operation mode and the selection of
either binary or BCD ( binary coded decimal ) counting format. The register can
only be written to. You can't read information from the register.
Control Word Register
All of the operating modes for the counters are selected by writing bytes to the
control register. This is the control word format.
Bits D7 and D6 are labeled SC1 and SC0. These bits select the counter to be
programmed, it is necessary to define, using the control bits D7 and D6, which
counter is being set up.
Page 151
Once a counter is set up, it will remain that way until it is changed by another
control word.
CONTROL BYTE D7 - D0
D5
D4 D3 D2 D1
RL1 RL0 M2 M1 M0
D7
SC1
D6
SC0
D7
SC1
0
0
1
1
D6
SC0
0
1
0
1
Counter Select
D5
RL1
0
D4
RL0
0
R / L Definition
0
1
1
1
0
1
D0
BCP
counter 0
counter 1
counter 2
illegal value
Bits D5 and D4 ( RL1 / RL0 ) of the control word shown above are defined as the
read / load mode for the register that is selected by bits D7 and D6. Bits D5 and
D4 define how the particular counter is to have data read from or written to it by
the CPU.
These bits are defined as:
The 1st value,00, is the counter latch mode. If this mode is specified, the current
counter value is latched into an internal register at the time of the I/O write
operation to the control register. When a read of the counter occurs, it is this
latched value that is read.
Caution: If the latch mode is not used, then it is possible that the data read back
may be in the process of changing while the read is occurring. This could result
in invalid data being input by the CPU ( see the timing diagrams to the 8253 by
intel's site or go to page "Memory mapped I/O" ). To read the counter value
while the counter is still in the process of counting, one must first issue a latch
Page 152
control word, and then issue another control word that indicates the order of the
bytes to be read.
An alternative method of obtaining a stable count from the timer is to externally
inhibit counting while the register is being read. To this, an external logic to the
8253 controlled by the Z80 to inhibit count during an input read operation is to
connect. Each technique has certain disadvantages. The first, the latching
method, may give the CPU a reading that is "old" by several cycles, depending
on the speed of the count and which byte of the counter is being read. The
second method, the external inhibiting function, requires additional hardware. In
addition, it may change the overall system operation.
The input to counter 0 is 1.1088MHz.
The next 3 bits of the control word are D3, D2, and D1. These bits determine the
basic mode of operation for the selected counter. The mode descriptions follows:
D3
M2
0
0
x
x
1
1
D2
M1
0
0
1
1
0
0
D1
M0
0
1
0
1
0
1
Mode value
mode 0: interrupt on terminal count
mode 1: programmable one-shot
mode 2: rate generator
mode 3: square wave generator
mode 4: software triggered strobe
mode 5: hardware triggered strobe
The final bit D0 of the control register determines how the register will count:
The maximum values for the count in each count mode are 104 ( 10,000 decimal )
in BCD, and 216 ( 65,536 decimal ) in binary.
D0
0
1
counts down in
binary
BCD
Page 153
Fig:
Block Diagram
Of 8259
Page 154
Pin Description
The most common method of servicing such devices is the Polled approach. This
is where the processor must test each device in sequence and in effect ``ask'' each
Page 155
one if it needs servicing. It is easy to see that a large portion of the main program
is looping through this continuous polling cycle and that such a method would
have a serious detrimental effect on system throughput, thus limiting the tasks
that could be assumed by the microcomputer and reducing the cost effectiveness
of using such devices.
A more desirable method would be one that would allow the microprocessor to
be executing its main program and only stop to service peripheral devices when
it is told to do so by the device itself. In effect, the method would provide an
external asynchronous input that would inform the processor that it should
complete whatever instruction that is currently being executed and fetch a new
routine that will service the requesting device. Once this servicing is complete,
however, the processor would resume exactly where it left off.
This method is called Interrupt. It is easy to see that system throughput would
drastically increase, and thus more tasks could be assumed by the
microcomputer to further enhance its cost effectiveness.
The Programmable Interrupt Controller (PIC) functions as an overall manager in
an Interrupt-Driven system environment. It accepts requests from the peripheral
equipment, determines which of the incoming requests is of the highest
importance (priority), ascertains whether the incoming request has a higher
priority value than the level currently being serviced, and issues an interrupt to
the CPU based on this determination.
Each peripheral device or structure usually has a special program or ``routine''
that is associated with its specific functional or operational requirements; this is
referred to as a ``service routine''. The PIC, after issuing an Interrupt to the CPU,
must somehow input information into the CPU that can ``point'' the Program
Counter to the service routine associated with the requesting device. This
``pointer'' is an address in a vectoring table and will often be referred to, in this
document, as vectoring data.
Page 156
The 8259A is a device specifically designed for use in real time, interrupt driven
microcomputer systems. It manages eight levels or requests and has built-in
features for expandability to other 8259A's (up to 64 levels). It is programmed by
the system's software as an I/O peripheral. A selection of priority modes is
available to the programmer so that the manner in which the requests are
processed by the 8259A can be configured to match his system requirements. The
priority modes can be changed or reconfigured dynamically at any time during
the main program. This means that the complete interrupt structure can be
defined as required, based on the total system environment.
INTERRUPT REQUEST REGISTER (IRR) AND IN-SERVICE REGISTER (ISR)
The interrupts at the IR input lines are handled by two registers in cascade, the
Interrupt Request Register (IRR) and the In-Service (ISR). The IRR is used to store
all the interrupt levels which are requesting service; and the ISR is used to store
all the interrupt levels which are being serviced.
PRIORITY RESOLVER
This logic block determines the priorities of the bits set in the IRR. The highest
priority is selected and strobbed into the corresponding bit of the ISR during
INTA pulse.
INTERRUPT MASK REGISTER (IMR)
The IMR stores the bits which mask the interrupt lines to be masked. The IMR
operates on the IRR. Masking of a higher priority input will not affect the
interrupt request lines of lower quality.
INT (INTERRUPT)
This output goes directly to the CPU interrupt input. The VOH level on this line
is designed to be fully compatible with the 8080A, 8085A and 8086 input levels.
INTA (INTERRUPT ACKNOWLEDGE)
INTA pulses will cause the 8259A to release vectoring information onto the data
bus. The format of this data depends on the system mode (mPM) of the 8259A.
DATA BUS BUFFER
Compiled by : Dr.. Manoj V.N.V.
Page 157
This 3-state, bidirectional 8-bit buffer is used to interface the 8259A to the system
Data Bus. Control words and status information are transferred through the Data
Bus Buffer.
READ/WRITE CONTROL LOGIC
The function of this block is to accept OUTput commands from the CPU. It
contains the Initialization Command Word (ICW) registers and Operation
Command Word (OCW) registers which store the various control formats for
device operation. This function block also allows the status of the 8259A to be
transferred onto the Data Bus.
CS (CHIP SELECT)
A LOW on this input enables the 8259A. No reading or writing of the chip will
occur unless the device is selected.
WR (WRITE)
A LOW on this input enables the CPU to write control words (ICWs and OCWs)
to the 8259A.
RD (READ)
A LOW on this input enables the 8259A to send the status of the Interrupt
Request Register (IRR), In Service Register (ISR), the Interrupt Mask Register
(IMR), or the Interrupt level onto the Data Bus.
A0
This input signal is used in conjunction with WR and RD signals to write
commands into the various command registers, as well as reading the various
status registers of the chip. This line can be tied directly to one of the address
lines.
THE CASCADE BUFFER/COMPARATOR
This function block stores and compares the IDs of all 8259A's used in the
system. The associated three I/O pins (CAS0-2) are outputs when the 8259A is
used as a master and are inputs when the 8259A is used as a slave. As a master,
the 8259A sends the ID of the interrupting slave device onto the CAS02 lines.
Compiled by : Dr.. Manoj V.N.V.
Page 158
The slave thus selected will send its preprogrammed subroutine address onto the
Data Bus during the next one or two consecutive INTA pulses.
INTERRUPT SEQUENCE
The powerful features of the 8259A in a microcomputer system are its
programmability and the interrupt routine addressing capability. The latter
allows direct or indirect jumping to the specific interrupt routine requested
without any polling of the interrupting devices. The normal sequence of events
during an interrupt depends on the type of CPU being used.
The events occur as follows in an MCS-80/85 system:
1. One or more of the INTERRUPT REQUEST lines (IR70) are raised high,
setting the corresponding IRR bit(s).
2. The 8259A evaluates these requests, and sends an INT to the CPU, if
appropriate.
3. The CPU acknowledges the INT and responds with an INTA pulse.
4. Upon receiving an INTA from the CPU group, the highest priority ISR bit is
set, and the corresponding IRR bit is reset. The 8259A will also release a CALL
instruction code (11001101) onto the 8-bit Data Bus through its D70 pins.
5. This CALL instruction will initiate two more INTA pulses to be sent to the
8259A from the CPU group.
6. These two INTA pulses allow the 8259A to release its preprogrammed
subroutine address onto the Data Bus. The lower 8-bit address is released at the
first INTA pulse and the higher 8-bit address is released at the second INTA
pulse.
7. This completes the 3-byte CALL instruction released by the 8259A. In the
AEOI mode the ISR bit is reset at the end of the third INTA pulse. Otherwise, the
ISR bit remains set until an appropriate EOI command is issued at the end of the
interrupt sequence. The events occuring in an 8086 system are the same until step
4.
Page 159
4. Upon receiving an INTA from the CPU group, the highest priority ISR bit is set
and the corresponding IRR bit is reset. The 8259A does not drive the Data Bus
during this cycle.
5. The 8086 will initiate a second INTA pulse. During this pulse, the 8259A
releases an 8-bit pointer onto the Data Bus where it is read by the CPU.
6. This completes the interrupt cycle. In the AEOI mode the ISR bit is reset at the
end of the second INTA pulse. Otherwise, the ISR bit remains set until an
appropriate EOI command is issued at the end of the interrupt subroutine.
If no interrupt request is present at step 4 of either sequence (i.e., the request was
too short in duration) the 8259A will issue an interrupt level 7. Both the vectoring
bytes and the CAS lines will look like an interrupt level 7 was requested. When
the 8259A PIC receives an interrupt, INT becomes active and an interrupt
acknowledge cycle is started. If a higher priority interrupt occurs between the
two INTA pulses, the INT line goes inactive immediately after the second INTA
pulse. After an unspecified amount of time the INT line is activated again to
signify the higher priority interrupt waiting for service. This inactive time is not
specified and can vary between parts. The designer should be aware of this
consideration when designing a system which uses the 8259A. It is
recommended that proper asynchronous design techniques be followed.
Page 160