Unit 3
Unit 3
Unit 3
IO INTERFACING
Interfacing
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
requires 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 themicroprocessor.
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.
PA7-PA0: These are eight port A lines that acts as either latched output or buffered input lines depending
upon the control word loaded into the control word register.
PC7-PC4: Upper nibble of port C lines. They may act as either output latches or input buffers lines. This
port also can be used for generation of handshake lines in mode 1 or mode 2.
PC3-PC0: These are the lower port C lines, other details are the same as PC7-PC4 lines.
PB0-PB7: These are the eight port B lines which are used as latched output lines or buffered input lines
in the same way as port A.
RD: This is the input line driven by the microprocessor and should be low to indicate read operation to
8255.
WR: This is an input line driven by the microprocessor. A low on this line indicates write operation.
CS: This is a chip select line. If this line goes low, it enables the 8255 to respond to RD and WR signals,
otherwise RD and WR signal are neglected.
A1-A0: These are the address input lines and are driven by the microprocessor. These lines A1-A0 with
RD, WR and CS from the following operations for 8255. In case of 8086 systems, if the 8255 is to be
interfaced with lower order data bus, the A0 and A1 pins of 8255 are connected with A1 and A2
respectively.
D0-D7: These are the data bus lines those carry data or control word to/from the microprocessor.
RESET: A logic high on this line clears the control word register of 8255. All ports are set as input ports
by default after reset.
8255 Block Diagram:
(CS) Chip Select. A "low" on this input pin enables the communication between the 8255
and the CPU.
(RD) Read. A "low" on this input pin enables 8255 to send the data or status information
to the CPU on the data bus. In essence, it allows the CPU to "read from" the 8255.
(WR) Write. A "low" on this input pin enables the CPU to write data or control words
into the 8255.
(A0 and A1) Port Select 0 and Port Select 1. These input signals, in conjunction with the
RD and WR inputs, control the selection of one of the three ports or the control word
register. They are normally connected to the least significant bits of the address bus (A0
and A1).
(RESET) Reset. A "high" on this input initializes the control register to 9Bh and all ports
(A, B, C) are set to the input mode.
A1 A0 SELECTION
0 0 PORT A
0 1 PORT B
1 0 PORT C
1 1 CONTROL
There are two different control word formats which specify two basic modes:
BSR (Bit set reset)mode
I/O mode
The two basic modes are selected by D7 bit of control register. When D7=1 it is an I/O mode and when
D7=0; it is a BSR mode.
BSR mode-
1. The BSR mode is a port C bit set/resetmode.
2. The individual bit of port C can be set or reset by writing control word in the
controlregister.
3. The control word format of BSR mode is as shown in the figurebelow
1. The pin of port C is selected using bit select bits [b b b] and set or reset is decided by bit S/R.̅
2. The BSR mode affects only one bit of port C at a time. The bit set using BSR mode remains set
unless and until you change the bit. So to set any bit of port C, bit pattern is loaded in control
register.
3. If a BSR mode is selected it will not affect I/Omode.
I/O modes
There are three I/O modes of operation:
Mode 0- BasicI/O
Mode 1- StrobedI/O
Mode 2- Bi-directionalI/O
The I/O modes are programmed using control register.
The control word format of I/O modes is as shown in the figure below:
[Source: Advanced Microprocessors and Microcontrollers by A.K Ray & K.M.
Bhurchandi]
Function of each bit is as follows:
1. D7– When the bit D7 = 1 then I/O mode is selected, if D7=0 then BSR mode is selected. The
function of bits D0 to D6 is independent on mode (I/O mode or BSRmode).
2. D6 and D5-In I/O mode the bits D6 and D5 specifies the different I/O modes for group A i.e.
Mode 0, Mode 1 and Mode 2 for port A and port Cupper.
3. D2 – In I/O mode the bit D2 specifies the different I/O modes for group B i.e. Mode 0 and Mode
1 forport
B and port C lower.
All the 3 modes i.e. Mode 0, Mode 1 and Mode 2 are only for group A ports, but for group B only 2
modes i.e. Mode 0 and Mode 1 are provided. When 8255 is reset, it will clear control word register
contents and all the ports are set to input mode. The ports of 8255 can be programmed for other modes by
sending appropriate bit pattern to control register.
[Source: Advanced Microprocessors and Microcontrollers by A.K Ray & K.M.
Bhurchandi]
ü I/O Modes of 8255
INTERFACE(INTEL 8251)
The 8251 is a programmable chip designed for synchronous and asynchronous serial data communication.
converting parallel data to serial form and vice versa Two types of serial data communications are widely
used
Asynchronous communications
Synchronous communications
Control Words
There are two types of control word.
1. Mode instruction (setting offunction)
2. Command (setting ofoperation)
1) ModeInstruction
Mode instruction is used for setting the function of the 8251. Mode instruction will be in "wait for write"
at either internal reset or external reset. That is, the writing of a control word after resetting will be
recognized as a "mode instruction."
Items set by mode instruction are as follows:
• Synchronous/asynchronousmode
• Stop bit length (asynchronousmode)
• Characterlength
• Paritybit
• Baud rate factor (asynchronousmode)
• Internal/external synchronization (synchronousmode)
• Number of synchronous characters (Synchronousmode)
The bit configuration of mode instruction is shown in Figures 2 and 3. In the case of synchronous mode, it
is necessary to write one-or two byte sync characters. If sync characters were written, a function will be
set because the writing of sync characters constitutes part of mode instruction.
[Source: Advanced Microprocessors and Microcontrollers by A.K Ray & K.M.
Bhurchandi]
2) Command
Command is used for setting the operation of the 8251. It is possible to write a command whenever
necessary after writing a mode instruction and sync characters. Items to be set by command are as
follows:
• Transmit Enable/Disable
• ReceiveEnable/Disable
• DTR, RTS Output of data.
• Resetting of errorflag.
• Sending to breakcharacters
• Internalresetting
• Hunt mode (synchronous mode)
Status Word
It is possible to see the internal status of the 8251 by reading a status word. The bit configuration of status
word is shown in Fig. 5.
8253 8254
Its operating frequency is 0 - 2.6 MHz Its operating frequency is 0 - 10 MHz
It uses N-MOS technology It uses H-MOS technology
Read-Back command is not available Read-Back command is available
Reads and writes of the same counter cannot be Reads and writes of the same counter can be
interleaved. interleaved.
Features of 8253 / 54
The most prominent features of 8253/54 are as follows −
It has three independent 16-bit down counters. These three counters can be programmedfor
either binary or BCDcount.
It can handle inputs from DC to 10MHz.
It is compatible with almost allmicroprocessors.
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 thecounter.
8254 Architecture and Pin Description
PIN DETAILS OF 8254
CS - Chip select .When it is low,enables the communication between CPU and 8253.
WR-When it is low,the CPU output data in the form of mode information are loading counters.
RD – When it is low,the CPU reads data.
A0-A1: These pins are connected to address bus. These are used to select one of the three counters.
D0-D7: These are tri-state bidirectional data bus used to interface 8253 to the system data bus.
CLK0,CLK1,CLK2-These are clock signals for counter0,counter1 and counter2.
GATE0,GATE1,GATE2- These are gate terminals for counter0, counter1 and counter2.
OUT0,OUT1,OUT2- These are output terminals for counter0, counter1 and counter2.
[Source: Advanced Microprocessors and Microcontrollers by A.K Ray & K.M.
Bhurchandi]
In the above figure, there are three counters, a data bus buffer, Read/Write control logic, and a
control register. Each counter has two input signals - CLOCK & GATE, and one output signal - OUT.
Data Bus Buffer
It is a tri-state, bi-directional, 8-bit buffer, which is used to interface the 8253/54 to the system data bus.
It has three basic functions −
Read/Write Logic
It includes 5 signals, i.e. RD, WR, CS, and the address lines A0 & A1. In the peripheral I/O mode, the
RD and WR signals are connected to IOR and IOW, respectively. In the memory mapped I/O mode,
these are connected to MEMR andMEMW.
Address lines A0 & A1 of the CPU are connected to lines A0 and A1 of the 8253/54, and CS is tied to a
decoded address. The control word register and counters are selected according to the signals on lines
A0 & A1.
A1 A0 Result
0 0 Counter 0
0 1 Counter 1
1 0 Counter 2
1 1 Control Word Register
X X No Selection
Control Word Register
This register is accessed when lines A0 & A1 are at logic 1. It is used to write a command word,
which specifies the counter to be used, its mode, and either a read or write operation.
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
1 1 1 0 0 Write Control Word
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
Counters
Each counter consists of a single, 16 bit-down counter, which can be operated in either binary or
BCD. Its input and output is configured by the selection of modes stored in the control word register.
The programmer can read the contents of any of the three counters without disturbing the actual count in
process.
When the pins A0,A1 are 11,the control word register is selected.
The bits D7 and D6 of the control word are to select one of the 3 counters.D5 and D4 are for loading
/reading the count.D3,D2 and D1 are for the selection of operating mode of the selected counter.
Operation of 8253:
The complete functional definition of the 8253/54 is programmed by the system software. Once
programmed, the 8253/54 is ready to perform whatever timing tasks it is assigned to accomplish.
WRITE Operation:
2. Counter Latch Command : In the second method, an appropriate control word is written
into the control register to latch a count in the output latch, and two I/O read operations are performedby
the CPU. The first I/O operation reads the low-order byte, and the second I/O operation reads the high
orderbyte.
3. Read-Back Command (Available only for 8254) : The third method uses the Read-Back
command. This command allows the user to check the count value, programmed Mode, and current
status of the OUT pin and Null count flag of the selectedcounter(s).
Below figure shows the format of the control word register for Read-Back command.
The process of decrementing the counter continues till the terminal count is reached i.e., the
count becomes zero and output goes HIGH.The output remains high until it reloads a new mode of
operation or newcount.
The GATE signal is high for normal counting .When GATE goes low counting is terminated
and the current count is latched till the GATE goes high again.
The gate input is used as trigger input in this mode. Normally, the output remains high until the count
is loaded and a trigger is applied.
When the count N is loaded is EVEN,half of the count will be high and half of the count
will below.
When,the count N is loaded is ODD,the N+1/2 count will be high and N-1/2 will be low.
The counter automatically begins to decrement (count down) one clock pulse after it is
loaded with the initial value isloaded.
When the GATE signal goes low the count is latched
Once the terminal count,the output goes low for one clock cycle and then again goes
high.this low pulse can be used astrobe.
[Source: Advanced Microprocessors and Microcontrollers by A.K Ray & K.M.
Bhurchandi]
This mode generates a strobe in response to an externally generated signal.It is similar to mode 4
except that the counting is initiated by a signal at the gate input.
The counter starts counting after the rising edge of the trigger input(GATE)
When the terminal count is reached,the output goes low for one clock cycle.
In the Interrupt mode, the processor is requested service only if any key is pressed, otherwise the CPU
will continue with its main task.
In the Polled mode, the CPU periodically reads an internal flag of 8279 to check whether any key is
pressed or not with key pressure.
If a FIFO contains a valid key entry, then the CPU is interrupted in an interrupt mode else the CPU
checks the status in polling to read the entry. Once the CPU reads a key entry, then FIFO is updated, and
the key entry is pushed out of the FIFO to generate space for new entries.
Scan Counter
It has two modes i.e. Encoded mode and Decoded mode. In the encoded mode, the counter provides the
binary count that is to be externally decoded to provide the scan lines for the keyboard and display.
In the decoded scan mode, the counter internally decodes the least significant 2 bits and provides a
decoded 1 out of 4 scan on SL0-SL3.
key entry. In case, the same key is detected, then the code of that key is directly transferred to the sensor
RAM along with SHIFT & CONTROL key status.
In the scanned sensor matrix mode, this unit acts as sensor RAM where its each row is loaded with the
status of their corresponding row of sensors into the matrix. When the sensor changes its state, the IRQ
line changes to high and interrupts the CPU.
CLK
The clock input is used to generate internal timings required by the microprocessor.
RESET
As the name suggests this pin is used to reset the microprocessor.
CS Chip Select
When this pin is set to low, it allows read/write operations, else this pin should be set to high.
A0
This pin indicates the transfer of command/status information. When it is low, it indicates the transfer of
data.
RD, WR
This Read/Write pin enables the data buffer to send/receive data over the data bus.
IRQ
This interrupt output line goes high when there is data in the FIFO sensor RAM. The interrupt line goes
low with each FIFO RAM read operation. However, if the FIFO RAM further contains any key-code
entry to be read by the CPU, this pin again goes high to generate an interrupt to the CPU.
Vss, Vcc
These are the ground and power supply lines of the microprocessor.
SL0 − SL3
These are the scan lines used to scan the keyboard matrix and display the digits. These lines can be
programmed as encoded or decoded, using the mode control register.
RL0 − RL7
These are the Return Lines which are connected to one terminal of keys, while the other terminal of the
keys is connected to the decoded scan lines. These lines are set to 0 when any key is pressed.
SHIFT
The Shift input line status is stored along with every key code in FIFO in the scanned keyboard mode.
Till it is pulled low with a key closure, it is pulled up internally to keep it high
BD
It stands for blank display. It is used to blank the display during digit switching.
OUTA0 – OUTA3 and OUTB0 – OUTB3
These are the output ports for two 16x4 or one 16x8 internal display refresh registers. The data from
these lines is synchronized with the scan lines to scan the display and thekeyboard.
Input Mode
This mode deals with the input given by the keyboard and this mode is further classified into 3 modes.
Scanned Keyboard Mode − In this mode, the key matrix can be interfaced using either encoded
or decoded scans. In the encoded scan, an 8×8 keyboard or in the decoded scan, a 4×8keyboard
can be interfaced. The code of key pressed with SHIFT and CONTROL status is stored into the
FIFO RAM.
Scanned Keyboard Mode with 2 KeyLockout
In this mode of operation, when a key is pressed, debounce logic comes into operation. The Key
code of the identified key is entered into the FIFO with SHIFT and CNTL status, provided the
FIFO is not full.
Scanned Keyboard with N-keyRollover
In this mode, each key depression is treated independently. When a key is pressed, the debounce
circuit waits for 2 keyboard scans and then checks whether the key is still depressed. If it is still
depressed, the code is entered in FIFO RAM. Any number of keys can be pressed simultaneously
and recognized in the order, the Keyboard scan record them.
1. Scanned Keyboard Special ErrorMode
This mode is valid only under the N-Key rollover mode. This mode is programmed using end
interrupt/error mode set command. If during a single debounce period (two Keyboard scan) two
keys are found pressed, this is considered a simultaneous depression and an error flag is set. This
flag, if set, prevents further writing in FIFO but allows generation of further interrupts to the CPU
for FIFO read.
Scanned Sensor Matrix − In this mode, a sensor array can be interfaced with the processor
using either encoder or decoder scans. In the encoder scan, 8×8 sensor matrix or with decoder
scan 4×8 sensor matrix can beinterfaced.
Strobed Input − In this mode, when the control line is set to 0, the data on the return lines is
stored in the FIFO byte bybyte.
Output Mode
This mode deals with display-related operations. This mode is further classified into two output modes.
Display Scan − This mode allows 8/16 character multiplexed displays to be organized as dual 4-
bit/single 8-bit displayunits.
Display Entry − This mode allows the data to be entered for display either fromthe
o right entry (CalculatorType)
o left entry
Command Words of8279
All the command words or status words are written or read with A0 = 1 and CS = 0 to or from 8279. This
section describes the various command available in 8279.
a) Keyboard Display Mode Set – The format of the command word to select different modes of
operation of 8279 is given below with its bitdefinitions.
Read Display RAM :
The 8259A is a programmable interrupt controller specially designed to work with Intel
microprocessor 8080, 8085A, 8086, 8088. The main features of 8259A programmable interrupt
controller are given below:
1) It can handle eight interrupt inputs. This is equivalent to providing eight interrupt pins on
the processor in place of one INTR (in 8085A)/INT (in 8086)pin.
2) It can resolve eight levels of interrupt priorities in a variety of modes. The prioritiesof
interrupts can be changed under running condition.
3) Each of the interrupt requests can be masked individually similar to RST7.5,RST6.5
and RST5.5 interrupts of8085A.
4) The status of pending interrupts, in service interrupts, and masked interrupts can be readat
any time similar to RST interrupts of8085A.
6) The chip can be programmed to accept interrupt requests either as level triggered or edge
triggered interrupt request unlike your RST interrupts where some are edge triggered and
some are level triggered. However, all interrupts must be either level triggered or edge
triggered.
The 8259 A is contained in a 28 dual-in-line package that requires only +5V supply
voltage. The 8259A is upward compatible with 8259. The main difference between the two is that
the 8259A can be used with Intel 8086/8088 processor. It also includes additional features such as
level triggered mode, buffered mode and automatic end of interrupt mode.
The pin diagram and internal block diagram of PIC is shown in figure. The pins are
defined as follows:
CS (Chip Select signal): To access this chip, chip select signal CS is made low. A LOW on this
pin enables RD & WR communication between the CPU and the 8259A. This signal is made
LOW by decoding the addresses assigned to this chip. Therefore, this pin is connected to address
bus through the decoder logic circuit. Interrupt acknowledge functions to transfer the control to
interrupt service subroutine are independent of CS.
WR (Write signal): A low on this pin. When CS is low enables the 8259 A to accept command
words from CPU.
RD (Read signal): A low on this pin when CS is low enables this 8259A to release status
(pending interrupts or in-service interrupts or masked interrupts) on to the data bus for the CPU.
The status includes the contents of IMR (interrupt mask register) or ISR (interrupt service
register) or IRR (interrupt request register) or a prioritylevel.
D7-D0 (Data Bus): Bidirectional data bus. Control, status and interrupt vector information is
transferred via this data bus. This bus is connected to BDB of 8085A.
CAS2-CAS0 (Cascade lines): The CAS2-0 lines form a local 8259A bus to control multiple 8259As
in master-slave configuration, i.e., to identify a particular slave 8259A to be accessed for transfer
of vector information. These pins are automatically set as output pins for master 8259A and input
pins for a slave 8259A once the chips are programmed as master or slave.
SP/ EN (Salve Program/Enable Buffer): This is a dual function pin. When the chip is
programmed in buffered mode, the pin can be used as an output and when not in the buffered
mode it is used as an input. In non-buffered mode it is used as an input pin to determine whether
the 8259A is to be used as a master (SP/ EN = 1) or as a slave (SP/ EN =0).
INT (Interrupt output): This pin goes high whenever a valid interrupt request is asserted. It is
used to interrupt the CPU, thus it is connected to the CPU’s interrupt pin (INTR). In case of
master-slave
configuration, the interrupt pin of slave 8259A is connected to interrupt request input of master
8259A.
INTA (Interrupt Acknowledge): This pin is used to enable 8259A interrupt vector data on the
data bus by a sequence of interrupt acknowledge pulses issued by theCPU.
IR0-IR7 (Interrupt Request inputs): These are asynchronous interrupt request input pins. An
interrupt request is executed by raising an IR input (low to high), and holding it high until it is
acknowledged. (Edge triggered mode) or just by a high level on an interrupt request input (Level
triggered mode).
A0 (A0 address line): This pin acts in conjunction with the RD , WR & CS pins. It is used by the
8259A to send various command words from the CPU and to read the status. It is normally
connected to the CPU A0 address line. Two addresses are assigned/ reserved in the I/O address
space for each 8259A in the system- one with A0 =0 is called even address and other with A0 = 1
is called oddaddress.
FunctionalDescription:
The 8259A (PIC) has eight interrupt request inputs – IR7 - IR0. The 8259A uses its INT
output to interrupt the 8085A via INTR pin. The 8259A receives interrupt acknowledge pulses
from the at its INTA input. Vector address, used by the 8085A to transfer control to the service
subroutine of the interrupting device, is provided by the 8259A on the data bus. The 8259A is a
programmable device that must be initialized by command words sent by the microprocessor.
After initialization the 8259A mode of operation can be changed by operation command words
from themicroprocessor.
It contains followingblocks-
1. Data busbuffer-
It is used to transfer data between microprocessor and internalbus.
1. Read/writelogic-
It sets the direction of data busbuffer.
It controls all internal read/writeoperations.
It contains initialization and operation commandregisters.
Cascaded buffer and comparator-
In master mode, it functions as a cascaded buffer. The cascaded buffers output slave
identification number on cascade lines.
In slave mode, it functions as a comparator. The comparator reads slave identification
number from cascade lines and compares this number with its internal identification
number.
It is designed by Intel to transfer data at the fastest rate. It allows the device to transfer the data
directly to/from memory without any interference of the CPU.
Using a DMA controller, the device requests the CPU to hold its data, address and control bus, so the
device is free to transfer data directly to/from the memory. The DMA data transfer is initiated only
after receiving HLDA signal from the CPU.
How DMA Operations are Performed?
Initially, when any device has to send data between the device and the memory, the device has
to send DMA request (DRQ) to DMA controller.
The DMA controller sends Hold request (HRQ) to the CPU and waits for the CPU to assert
the HLDA.
Then the microprocessor tri-states all the data bus, address bus, and control bus. The CPU
leaves the control over bus and acknowledges the HOLD request through HLDA signal.
Now the CPU is in HOLD state and the DMA controller has to manage the operations over buses
between the CPU, memory, and I/O devices.
Features of 8257
It has four channels that can be used over four I/O devices.
Each channel has 16-bit address and 14-bitcounter.
Each channel can transfer data up to64kb.
Each channel can be programmed independently.
Each channel can perform read transfer, write transfer and verify transfer operations.
It operates in 2 modes, i.e., Master mode and Slave mode.
8257 Pin Description
DRQ0−DRQ3
These are the four individual channel DMA request inputs, which are used by the peripheral devices for
using DMA services. When the fixed priority mode is selected, then DRQ0 has the highest priority and
DRQ3 has the lowest priority among them.
DACKo − DACK3
These are the active-low DMA acknowledge lines, which updates the requesting peripheral about the
status of their request by the CPU. These lines can also act as strobe lines for the requesting devices.
Do − D7
These are bidirectional, data lines which are used to interface the system bus with the internal data bus of
DMA controller. In the Slave mode, it carries command words to 8257 and status word from 8257. In the
master mode, these lines are used to send higher byte of the generated address to the latch. This address is
further latched using ADSTB signal.
IOR
It is an active-low bidirectional tri-state input line, which is used by the CPU to read internal registers of
8257 in the Slave mode. In the master mode, it is used to read data from the peripheral devices during a
memory write cycle.
IOW
It is an active low bi-direction tri-state line, which is used to load the contents of the data bus to the 8-bit
mode register or upper/lower byte of a 16-bit DMA address register or terminal count register. In the
master mode, it is used to load the data to the peripheral devices during DMA memory read cycle.
CLK
It is a clock frequency signal which is required for the internal operation of 8257.
RESET
This signal is used to RESET the DMA controller by disabling all the DMA channels.
Ao - A3
These are the four least significant address lines. In the slave mode, they act as an input, which selectsone
of the registers to be read or written. In the master mode, they are the four least significant memory
address output lines generated by8257.
CS
It is an active-low chip select line. In the Slave mode, it enables the read/write operations to/from 8257. In
the master mode, it disables the read/write operations to/from 8257.
A4 - A7
These are the higher nibble of the lower byte address generated by DMA in the master mode.
READY
It is an active-high asynchronous input signal, which makes DMA ready by inserting wait states.
HRQ
This signal is used to receive the hold request signal from the output device. In the slave mode, it is
connected with a DRQ input line 8257. In Master mode, it is connected with HOLD input of the CPU.
HLDA
It is the hold acknowledgement signal which indicates the DMA controller that the bus has been granted
to the requesting peripheral by the CPU when it is set to1.
MEMR
It is the low memory read signal, which is used to read the data from the addressed memory locations
during DMA read cycles.
MEMW
It is the active-low three state signal which is used to write the data to the addressed memory location
during DMA write operation.
ADST
This signal is used to convert the higher byte of the memory address generated by the DMA controller
into the latches.
AEN
This signal is used to disable the address bus/data bus.
TC
It stands for ‘Terminal Count’, which indicates the present DMA cycle to the present peripheral devices.
MARK
The mark will be activated after each 128 cycles or integral multiples of it from the beginning. It indicates
the current DMA cycle is the 128th cycle since the previous MARK output to the selected peripheral
device.
Vcc
It is the power signal which is required for the operation of the circuit.
Internal Architecture of 8257:
The 8-bit. Tristate, bidirectional buffer interfaces the internal bus of 8257 with the external system
Read/Write Logic:
In the slave mode, the read/write logic accepts the I/O Read or I/O Write signals, decodes the
Ao-A3 lines and either writes the contents of the data bus to the addressed internal register or reads the
contents of the selected register depending upon whether IOW or IOR signal is activated.
In master mode, the read/write logic generates the IOR and IOW signals to control the data
Control Unit:
The control logic controls the sequences of operations and generates the required control signals like
AEN, ADSTB, MEMR,MEMW, TC and MARK along with the address lines A4-A7, in master mode.
Priority Resolver:
The priority resolver resolves the priority of the four DMA channels depending upon whether normal
The 8257 perfroms DMA operation over four independent DMA channels such as
1. DMA AddressRegister
Each DMA channel has one DMA address register. The function of this register is to store the
address of the starting memory location, which will be accessed by the DMA channel. The device that
wants to transfer data over a DMA channel, will access the block of the memory with the starting address
stored in the DMA Address Register.
2. Terminal Count Registers
Each of the four DMA channels of 8257 has one terminal count register (TC). This 16-bit register
isused for ascertaining that the data transfer through a DMA channel ceases or stops after the required
number of DMA cycles.
After each DMA cycle, the terminal count register content will be decremented by one and
finally it becomes zero after the required number of DMA cycles are over.
The bits 14 and 15 of this register indicate the type of the DMA operation (transfer).
The mode set register is used for programming the 8257 as per the requirements of the system. The
function of the mode set register is to enable the DMA channels individually and also to set the various
modes of operation.
[Source: Advanced Microprocessors and Microcontrollers by A.K Ray &
K.M. Bhurchandi]
The bits Do-D3 enable one of the four DMA channels of 8257
If the TC STOP bit is set, the selected channel is disabled after the terminal count condition is
If the TC STOP bit is programmed to be zero, the channel is not disabled, even after the count
reaches zero and further request are allowed on the same channel.
The auto load bit, if set, enables channel 2 for the repeat block chaining operations, without immediate
The extended write bit, if set to ‘1’, extends the duration of MEMW and IOW signals by activating
them earlier, this is useful in interfacing the peripherals with different access times.
4. Status register
The lower order 4-bits of this register contain the terminal count status for the four individual channels.
If any of these bits is set, it indicates that the specific channel has reached the terminal count condition.
The update flag is not affected by the read operation. This flag can only be cleared by resetting 8257.
The update flag is set every time, the channel 2 registers are loaded with contents of the channel 3
registers. It is cleared by the completion of the first DMA cycle of the new block. This register can only
read.
as 1.DMA operation
2. Write Operation
3.ReadOperation
The complete Operational sequence of 8257 is described in below state diagram.
The 8257 request any one of the 8257 DRQ inputs to transfer single byte.
In response to the request, the 8257 sends HRQ signal to CPU at its HLD input and waits
for acknowledgement at the HLDA input.
If the DMA controller receives the HLDA signal it indicates that the bus is available for
the transfer.
The DMA controllers generate the read and write commands to transfer the byte from/to the
I/O Device.
The DACK line of the used channel is pulled down by the dma controller to I/O device that
its request for DMA transfers.
The HRQ line is lowered by the DMA controller to indicate the CPU that it may regain
the control of the bus.
The DRQ must be high until acknowledged and must go low before S4 state of the
DMA operation state diagram to avoid another unwanted transfer.
In each s4 state ,the DRQ lines are sampled and highest priority request is recognized during
next transfer. The HRQ line is maintained active till all the DRQ line go low.
READY input used to interface 8257 with low speed devices. It is checked in s3 of the state
diagram . S3=0 ,8257 enter wait state. S3=1 ,8257 continues from s4 to complete the transfer.
Interfacing DMA controller(8257) with 8086
If DMA controller is initialized by a CPU properly, it is ready to take control of the
system bus on a DMA request, either from a peripheral or itself (in case of memory- to memory
transfer). The DMA controller sends a HOLD request to the CPU and waits for the CPU to assert the
HLDA signal. The CPU relinquishes the control of the bus before asserting the HLDA signal.
Once the HLDA signal goes high, the DMA controller activates the DACK signal to the requesting
peripheral and gains the control of the system bus. The DMA controller is the sole master of the bus, till
the DMA operation is over. The CPU remains in the HOLD status (all of its signals are tristate except
HOLD and HLDA), till the DMA controller is the master of the bus.
The DMA controller interfacing circuit implements a switching arrangement for the address, data and
control busses of the memory and peripheral subsystem from/to the CPU to/from the DMA controller.