CST307 - M4 Ktunotes - in
CST307 - M4 Ktunotes - in
• It has 3 8-bit ports, all ports are bidirectional (Can be used as Input port or output
port). They are Port – A (PA) and PB, PC. Port A contains one 8-bit output latch/buffer
and one 8-bit input buffer.
• Port B is similar to PORT A.
• Port C can be split into two parts, i.e. PORT C lower (PC0-PC3) and PORT C upper
(PC7-PC4) by the control word.
These three ports are further divided into two groups, i.e. Group A includes PORT A and
upper PORT C. Group B includes PORT B and lower PORT C. These two groups can be
programmed in three different modes, i.e. the first mode is named as mode 0, the second mode
is named as Mode 1 and the third mode is named as Mode 2.
It has 24 input/output lines which may be individually programmed in two groups of twelve
lines each, or three groups of eight lines. The two groups of I/O pins are named as Group A
and Group B. Each of these two groups contains a subgroup of eight I/O lines called as 8-bit
port and another subgroup of four lines or a 4-bit port.
Thus, Group A contains an 8-bit port A along with a 4-bit port. C upper. The port A lines are
identified by symbols PA0-PA7 while the port C lines are identified as PC4-PC7. Similarly,
Group B contains an 8-bit port B, containing lines PB0-PB7 and a 4-bit port C with lower bits
PC0- PC3. The port C upper and port C lower can be used in combination as an 8-bit port C.
Both the port C are assigned the same address. Thus, one may have either three 8-bit I/O ports
Functional Descriptions
It is a tri-state 8-bit buffer, which is used to interface the microprocessor to the system
data bus. Data is transmitted or received by the buffer as per the instructions by the CPU.
Control words and status information is also transferred using this bus.
CS
It stands for Chip Select. A LOW on this input selects the chip and enables the communication
between the 8255A and the CPU. It is connected to the decoded address, and A0 & A1 are
connected to the microprocessor address lines.
CS A1 A0 Result
0 0 0 PORT A
0 0 1 PORT B
0 1 0 PORT C
0 1 1 Control Register
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 signals. Following is the table
showing their various signals with their result.
1. INPUT/OUTPUT MODE
There are three basic modes of operation than can be selected by the system software:
• 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.
In mode 0 each group can be used as input or output. Port A, port B and Port C can be used
as input or output. Port C has the specialty that it can be divided in to two nibbles upper and
lower. Both upper and lower can now be programmed to use as input or output. Mode 0 is also
known as input/output mode (I/O mode). Question arises how we can do so. Yes, it’s simple.
Just send a control word to 8255 and it will set itself according to your control word. The
control word for mode 0 is like this.
In mode 0 you can also access individual bits of port C. For bit set reset mode D7 will always
be 0.
In this mode only port b can be used (as an output port). Each line of port C (PC0 - PC7)
can be set/reset by suitably loading the command word register.no effect occurs in input-output
mode. The individual bits of port c can be set or reset by sending the signal OUT instruction to
the control register.
The Intel 8253 and 8254 are Programmable Interval Timers (PTIs) designed for
microprocessors to perform timing and counting functions using three 16-bit registers. Each
counter has 2 input pins, i.e. Clock & Gate, and 1 pin for “OUT” output. To operate a counter,
a 16-bit count is loaded in its register. On command, it begins to decrement the count until it
reaches 0, then it generates a pulse that can be used to interrupt the CPU.
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 Reads and writes of the same
counter 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.
Counters
Each counter consists of a single, 16 bit-down counter, which can be operated in either
binary or BCD. Its input and output are 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.
8253/54 can be operated in 6 different modes. In this chapter, we will discuss these
operational modes.
i. Mode 0 ─ Interrupt on Terminal Count
It is used to generate an interrupt to the microprocessor after a certain interval. Initially
the output is low after the mode is set. The output remains LOW after the count value is loaded
into the counter.
The process of decrementing the counter continues till the terminal count is reached,
i.e., the count become zero and the output goes HIGH and will remain high until it reloads a
new count.
Suppose any device which is connected to input-output port wants to transfer data to
memory, first of all it will send input-output port address and control signal, input-output read
to input-output port, then it will send memory address and memory write signal to memory
where data has to be transferred. In normal input-output technique the processor becomes busy
in checking whether any input-output operation is completed or not for next input-output
operation, therefore this technique is slow.
DMA stands for Direct Memory Access. 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.
This problem of slow data transfer between input-output port and memory or between two
memory is avoided by implementing Direct Memory Access (DMA) technique. This is faster
as the microprocessor/computer is bypassed and the control of address bus and data bus is given
to the DMA controller.
• 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.
Features of 8257
• It has four channels which can be used over four I/O devices.
• Each channel has 16-bit address and 14-bit counter.
• Each channel can transfer data up to 64kb.
• Each channel can be programmed independently.
• Each channel can perform read transfer, write transfer and verify transfer operations.
• It generates MARK signal to the peripheral device that 128 bytes have been
transferred.
• It requires a single-phase clock.
• Its frequency ranges from 250Hz to 3MHz.
• It operates in 2 modes, i.e., Master mode and Slave mode.
Modes of DMAC:
1. Single Mode – In this only one channel is used, means only a single DMAC is
connected to the bus system.
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.
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
selects one of the registers to be read or written. In the master mode, they are the four least
significant memory address output lines generated by 8257.
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.
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 to 1.
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
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.
It is the power signal which is required for the operation of the circuit.
8257 - Architecture
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.
• It has 24 input/ output lines which may be individually programmed into two groups of 12 lines each or
three groups with 8 lines of each.
• The two groups of I/O pin are named as Group A and Group B
• Each of these two groups contains a subgroup of 8 lines called 8 bit port and another 4 bit lines called
port.
• Thus group A contains a 8 bit port along with a 4 bit port C upper. The port A lines are identified by PA0
to PA7 while port C lines are identified by PC4 to PC7.
• Similarly group B contains 8 bit port identified by PB0 to PB7 and 4 bit port C lower identified by PC0 to
PC3.
• The port C upper and port C lower can be used in combination as 8 bit port C. both the port C are
assigned same address.
• All these ports can function independently either as input or output port.
• This can be achieved by programming the bits of internal registers of 8255 called as Control Word
Register (CWR).
• The 8 bit data buffer is controlled by read/write logic
• The read/write control logic manages all the internal and external transfers of both data and control
words.
• The 8 bit 3 state bidirectional buffer is used to interface the internal data bus with external system data
bus.
Pins Description
PA7 – PA0 These are 8 port A lines that act as either latched output buffer or buffered input lines depending
upon the control word loaded into CWR
PC7 – PC4 Upper nibble of port C. they might act as either output latches or input buffers. This port can also
be used for generation of handshaking lines in mode 1 or 2
PC3 – PC0 Lower nibble of port C. same as above
PB0 – PB7 These are 8 port B lines which are used as latched output lines or buffered input lines same as
port A
̅̅̅̅
𝑅𝐷 This input line is driven by the microprocessor and should be low to indicate read operation
̅̅̅̅̅
𝑊𝑅 For write operation it should be low
̅̅̅̅
𝐶𝑆 This is a chip select line. When it goes low it responds to RD/WR signals, otherwise neglected
A1 – A0 These are address lines driven by the microprocessor. These along with RD/ WR/CS forms the
following operations. These address lines are used for addressing any of 4 registers as shown in
below table.
D0 – D7 These are data bus lines which carry data or control word to/ from 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.
I/O Mode: 8255 has 3 input modes they are Mode 0, Mode 1 and Mode 2
INTR (Interrupt Request): this is active high input signal that can used to interrupt the CPU. Whenever an
input devise request service. INTR is set by a high at STB pin and high at IBF pin.
• It contains 3 16 bit independent counters, each with a maximum count rate of 10 MHz.
• It is thus possible to generate three totally independent delays or maintain three independent counters
simultaneously.
• All three counters may be independently controlled by programming three internal command word
registers.
• Thie 8 bit bidirectional data bit buffer interfaces internal circuit of 8254 to external microprocessor
system bus.
• Data is transmitted or received by the buffer depending upon the execution of IN or OUT instruction.
• The read/ wrote logic controls the direction of data buffer depending upon whether it is read or write
operation.
• Three counters are independent of each other in operation but are identical to each other in organization.
These are 16 bit presetable down counters able to operate either in BCD mode or hexadecimal mode.
• The mode control word register contains the information that can be used for writing or reading the
count value into or from respective count register using IN or OUT instruction.
• The specialty of the counters is that they can be easily read on a line without disturbing the clock input to
the counter.
• A0, A1 are address pins and required internally for addressing the mode control word registers and three
counter registers.
• The actual counter is labelled CE (for ``Counting Element''). It is a 16-bit presettable synchronous down
counter. OLM and OLL are two 8-bit latches. OL stands for ``Output Latch''; the subscripts M and L
stand for ``Most significant byte'' and ``Least significant byte'‘ respectively.
• Both are normally referred to as one unit and called just OL. These latches normally ``follow'‘ the CE,
but if a suitable Counter Latch Command is sent to the 8254, the latches ``latch'' the present count
until read by the CPU and then return to ``following'' the CE.
• One latch at a time is enabled by the counter's Control Logic to drive the internal bus. This is how the
16-bit Counter communicates over the 8-bit internal bus. Note that the CE itself cannot be read;
whenever you read the count, it is the OL that is being read.
• Similarly, there are two 8-bit registers called CRM and CRL (for ``Count Register''). Both are normally
referred to as one unit and called just CR.
• When a new count is written to the Counter, the count is stored in the CR and later transferred to the
CE. The Control Logic allows one register at a time to be loaded from the internal bus. Both bytes are
transferred to the CE simultaneously.
• CRM and CRL are cleared when the Counter is programmed. In this way, if the Counter has been
programmed for one byte counts (either most significant byte only or least significant byte only) the
other byte will be zero.
• It is treated by the system's software as an array of peripheral I/O ports; three are counters and the
fourth is a control register for MODE programming
At the time of programming the timer it is necessary that each individual counter of 8254 is to be
programmed separately using control word and count value.
PIN DESCRIPTION
Pins Description
A0, A1 The address input selects one of four counter registers within 8254
A1 A0 Function
0 0 Counter 0
0 1 Counter 1
1 0 Counter 2
1 1 Control word
D0 – D7 Bidirectional three state data bus lines connected to system data bus
CLK Clock input is timing source for each counters. This input is often connected with PCLK
signal from the microprocessor system bus controller.
OUT Counter output where the waveform generated by it is available.
RD Read causes data to be read from 8254 and often connected to IORC signal
WR Write causes data to be written to 8254 and often connected to IOWC signal
Mode 0: This is used for event counting. After writing the control word, OUT is low at first. It will remain
low until the counter reaches 0, it is decremented by 1 after each clock cycle. Then the OUT goes high and
remains high until a new count is there or a new Mode 0 control word is written into the counter. The GATE
= 1 indicates enable counting, and 0 indicates disable counting
Mode 1: also called as programable one shot mode. This can be used as monostable vibrator. OUT will be
high at first, it will go Low on the clock pulse following a trigger to begin the one-shot pulse. It will remain
0 until the counter reaches 0. If another count is loaded when the output is already low, it will not disturb the
previous count till a new trigger pulse is applied at GATE input.
Mode 2: also called either rate generator or divide by N counter. In this the mode, if N is loaded as count
value then after N – 1 cycle, the output becomes low only for one clock cycle. The count N is reloaded again
and after N – 1 cycles output becomes high. The counter generates active low signals at output initially, after
the count register is loaded with a count value. Then count down starts and whenever count becomes zero
another active low pulse is generated at the output. The duration of these low pulses equal to one clock
cycle.
Mode 3: Also called square wave generator. When the count N is loaded is even, then for the half of the
count the output remains high and rest of the half it remains low. If the count loaded is odd, first clock cycle
decrements it by 1 resulting in even count. Then output remains high for first half and low for remaining
half. The process is repeated continuously, resulting in generation of square wave. In case of odd count, the
output is high for longer duration and low for shorter duration. In general, if loaded count value N is odd it
remains high for (N +1)/2 pulses and low for (N -1)/2 pulses.
Mode 5 (Hardware Triggered Strobe) – OUT will initially be high. Counting is triggered by a rising edge of
GATE. When the initial count has expired, OUT will go low for one clock pulse and then go high again.
After writing the Control Word and initial count, the counter will not be loaded until the clock pulse after a
trigger.
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.
8257 ARCHITECTURE
• The chip support four DMA channels, i.e. four peripheral devices can independently request for DMA
data transfer through these channels at a time.
• The DMA controller has 8-bit internal data buffer, a read/write unit, a control unit, a priority resolving
unit along with a set of registers.
• The 8257 performs the DMA operation over four independent DMA channels.
• Each of four channels of 8257 has a pair of two 16-bit registers, viz. DMA address register and terminal
count register.
• Also, there are two common registers for all channels namely mode set register and status register.
• Thus, there are total of 10 registers and CPU selects one of these using address lines A0 – A3.
DMA Address Register: Each DMA Channel has one DMA register. The function of these registers is to
store the address of starting memory locations, which will be accessed by 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.
Terminal Count Register: Each of the four DMA channels of 8257 has one terminal count register (TC).
This 16-bit register issued for ascertaining that the data transfer through a DMA channel ceases or stops
after the required number of DMA cycles. The low order 14-bits of the terminal count register are initialized
with the binary equivalent of the number of required DMA cycles minus one. 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). If the device wants to write data into the memory, the DMA operation is called DMA write
operation. Bit 14 of the register in this case will be set to one and bit 15 will be set to zero.
Mode Set Register: 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 to set the
various modes of operation. The DMA channel should not be enabled till the DMA address register and the
Status Register: The status register of 8257 is shown in figure. 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. These bits remain set till either the status is
read by the CPU or the 8257 is reset.
• The update flag is not affected by the read operation. This flag can only be cleared by resetting 8257 or
by resetting the auto load bit of the mode set register.
• If the update flag is set, the contents of the channel 3 registers are reloaded to the corresponding registers
of channel 2 whenever the channel 2 reaches a terminal count condition, after transferring one block and
the next block is to be transferred using the auto load feature of 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.
Data Bus Buffer, Read/ Write Logic, Control Unit and Priority Resolver
• The 8-bit. Tristate, bidirectional buffer interfaces the internal bus of 8257 with the external system bus
under the control of various control signals.
• 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 flow to or
from the selected peripheral. 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.
• The priority resolver resolves the priority of the four DMA channels depending upon whether normal
priority or rotating priority is programmed.