Microprocessor and Microcontroller Unit 3 Lecture Notes (1)
Microprocessor and Microcontroller Unit 3 Lecture Notes (1)
1.1.1MEMORY INTERFACING
We have four common types of memory
Read only memory (ROM)
Flash memory (EEPROM)
Static Random access memory (SARAM)
Dynamic Random access memory (DRAM)
Pin connections
Common to all memory devices are: The address input, data output or input/outputs,
selection input and control input used to select a read or write operation.
Address connections
All memory devices have address inputs that select a memory location within the
memory device.
Address inputs are labeled from A0 to An.
Data connections
All memory devices have a set of data outputs or input/outputs.
Today many of them have bi-directional common I/O pins.
Selection connections
Each memory device has an input that selects or enables the memory device.
This kind of input is most often called a chip select (CS), chip enable (CE) or simply
select (S) input.
Fig: 3.1 Memory components illustrating the address, data and control connections
ROM
It read only memory permanently stores programs and data and data was always
present, even when power is disconnected. It is also called as nonvolatile memory.
RAM
RAM memory device has either one or two control inputs. If there is one control input it
is often called R/W.
This pin selects a read operation or a write operation only if the device is selected by the
selection input (CS).
If the RAM has two control inputs, they are usually labeled WE or W and OE or G.
(WE) write enable must be active to perform a memory write operation and OE must be
active to perform a memory read operation.
When these two controls WE and OE are present, they must never be active at the
same time.
EPROM
Erasable Programmable Read Only Memory is also erasable if exposed to high intensity
ultraviolet light for about 20 minutes or less, depending upon the type of EPROM as
shown in figure 3.2.
We have PROM (Programmable Read Only Memory)
RMM
Read Mostly Memory is also called the flash memory.
The flash memory is also called as an EEPROM (Electrically Erasable Programmable
ROM), EAROM (Electrically Alterable ROM), or a NOVROM (Nonvolatile ROM).
These memory devices are electrically erasable in the system, but require more time to
erase than a normal RAM.
A0 –A10 ADDRESSES
PD/PGM POWER DOWN PROGRAM/
CS CHIP SELECT
O0-O7 OUT PUTS
Table 3.1
Static Random access memory (SARAM)
Static RAM memory device retain data for as long as DC power is applied.
Because no special action is required to retain stored data, these devices are called as
static memory.
They are also called volatile memory because they will not retain data without power.
The main difference between a ROM and RAM is that a RAM is written under normal
operation, while ROM is programmed outside the computer and is only normally read.
The SRAM stores temporary data and is used when the size of read/write memory is
relatively small.
The control inputs of this RAM are slightly different from those presented earlier.
The OE pin is labeled G, the CS pin S and the WE pin W. This 4016 SRAM device has
11 address inputs and 8 data input/output connections
1.1.2 Block Diagram
Block diagram and pin diagram are shown in figure 3.3 and 3.4.
A 0 –A 10 ADDRESSES
_
WRITE ENABLE
W
_
CHIP SELECT
S
Table 3.2
Dynamic RAM
Whenever a large capacity memory is required in a microcomputer system, the memory
subsystem is generally designed using dynamic RAM because there are various
advantages of dynamic RAM is shown in figure 3.5.
The basic dynamic RAM cell uses a capacitor to store the charge as a representation of
data.
This capacitor is manufactured as a diode that is reverse biased so that the storage
capacitance comes into the picture.
This storage capacitance is utilized for storing the charge representation of data but the
reverse-biased diode has leakage current that tends to discharge the capacitor giving
rise to the possibility of data loss. To avoid this possible data loss, the data stored in a
dynamic RAM cell must be refreshed after a fixed time interval regularly.
The process of refreshing the data in RAM is called as Refresh cycle.
The refresh activity is similar to reading the data from each and every cell of memory,
independent of the requirement of microprocessor.
During this refresh period all other operations related to the memory subsystem are
suspended.
Hence the refresh activity causes loss of time, resulting in reduces system performance.
However keeping in view the advantages of dynamic RAM, like low power consumption,
high packaging density and low cost, most of the advanced computing system are
designed using dynamic RAM, at the cost of operating speed.
A dedicated hardware chip called as dynamic RAM controller is the most important part
of the interfacing circuit. The Refresh cycle is different from the memory read cycle in the
following aspects.
Table 3.3
CS A1 A0 Function
RD WR
X X 1 X X Data bus tristated
In the above program, port A is initialized as the output port for sending the digital data
as input to DAC. The ramp starts from the 0V (analog), hence AL starts with 00H.
To increment the ramp, the content of AL is increased during each execution of loop till it
reaches F2H. After that the saw tooth wave again starts from 00H, i.e. 0V(analog) and
the procedure is repeated.
The ramp period given by this program is precisely 1.000625 ms. Here the count F2H
has been calculated by dividing the required delay of 1ms by the time required for the
execution of the loop once.
The ramp slope can be controlled by calling a controllable delay after the OUT
instruction.
This single output line is the signal that is the final programmed output of the device.
Actual operation of the outline depends on how the device has been programmed. 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.
3.6.5 Internal 8253 register
Here is a list of the internal 8253 registers that will program the internal counters of the
8253:
Counter #0, #1, #2 Each counter is identical, and each consists of a 16-bit, pre-settable,
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
3.6.6 Modes
The following text describes all possible modes. The modes used in the MZ-700 and set
by the monitor's startup are mode 0, mode 2, and mode 3.
Mode 0 Interrupt on Terminal Count
The counter will be programmed to an initial value and afterwards counts down at
a rate equal to the input clock frequency. When the count is equal to 0, the OUT
pin will be a logical 1. The output will stay a logical 1 until the counter is reloaded
with a new value or the same value or until a mode word is written to the device.
Once the counter starts counting down, the GATE input can disable the internal
counting by setting the GATE to a logical 0.
Mode 1 Programmable One-Shot
In mode 1, the device can be setup to give an output pulse that is an integer
number of clock pulses. The one-shot is triggered on the rising edge of the GATE
input. If the trigger occurs during the pulse output, the 8253 will be retriggered
again.
Mode 2 Rate Generator
The counter that is programmed for mode 2 becomes a "divide by n" counter. The
OUT pin of the counter goes to low for one input clock period. The time between
the pulses of going low is dependent on the present count in the counter's register.
I mean the time of the logical 1 pulse.
Priority Resolver
This unit determines the priorities of the interrupt requests appearing simultaneously.
The highest priority is selected and stored into the corresponding bit of ISR during INTA
pulse.
The IR0 has the highest priority while the IR7 has the lowest one, normally in fixed
priority mode.
The priorities however may be altered by programming the 8259A in rotating priority
mode.
1.8.3 Interrupt Control Logic
This block manages the interrupt and interrupt acknowledge signals to be sent to the
CPU for serving one of the eight interrupt requests.
This also accepts the interrupt acknowledge (INTA) signal from CPU that causes the
8259A to release vector address on to the data bus.
Data Bus Buffer
This tristate bidirectional buffer interfaces internal 8259A bus to the microprocessor
system data bus.
Control words, status and vector information pass through data buffer during read or
write operations.
Read/Write Control Logic
This circuit accepts and decodes commands from the CPU.
This block also allows the status of the 8259A to be transferred on to the data bus.
Cascade Buffer/Comparator
This block stores and compares the ID‘s all the 8259A used in system.
The three I/O pins CASO-2 are outputs when the 8259A is used as a master.
The same pins act as inputs when the 8259A is in slave mode.
The 8259A in master mode sends the ID of the interrupting slave device on these lines.
The slave thus selected, will send its preprogrammed vector address on the data bus
during the next INTA pulse.
INT:
This pin goes high whenever a valid interrupt request is asserted. This is used to
interrupt the CPU and is connected to the interrupt input of CPU.
IR0 – IR7 (Interrupt requests):
These pins act as inputs to accept interrupt request to the CPU. In edge triggered mode.
An interrupt service is requested by raising an IR pin from a low to a high state and
holding it high until it is acknowledged, and just by latching it to high level, if used in level
triggered mode.
INTA (Interrupt acknowledge):
This pin is an input used to strobe-in 8259A interrupt vector data on to the data bus.
In conjunction with CS, WR and RD pins, this selects the different operations like, writing
command words, reading status word, etc.
1.8.4 Interrupt Sequence in an 8086-8259A system
One or more IR lines are raised high that set corresponding IRR bits.
8259A resolves priority and sends an INT signal to CPU.
The CPU acknowledge with INTA pulse.
Upon receiving an INTA signal from the CPU, the highest priority ISR bit is set and the
corresponding IRR bit is reset. The 8259A does not drive data during this period.
The 8086 will initiate a second INTA pulse. During this period 8259A releases an 8-bit
pointer on to a data bus from where it is read by the CPU.
This completes the interrupt cycle. The ISR bit is reset at the end of the second INTA
pulse if automatic end of interrupt (AEOI) mode is programmed. Otherwise ISR bit
remains set until an appropriate EOI command is issued at the end of interrupt
subroutine.
Command Words of 8259A
The command words of 8259A are classified in two groups
Initialization command words (ICW) and
Operation command words (OCW).
Initialization Command Words (ICW)
Before it starts functioning, the 8259A must be initialized by writing two to four command
words into the respective command word registers.
These are called as initialized command words.ICW1 and ICW2 are compulsory
command words in initialization sequence of 8259A while ICW3 and ICW4 are optional.
Operation Command Words:
Once 8259A is initialized it is ready for its normal function, i.e. for accepting the
interrupts but 8259A has its own way of handling the received interrupts called as modes
of operation. These modes of operations can be selected by programming, i.e. writing
three internal registers called as operation command words registers.
The data written into them is called as operational command words.
There are three operation command words
OCW1
OCW2
OCW3
Every bit corresponds to some operational feature of the mode selected, except for a
few bits those are either 1 or0.
Priority Resolver:
This block assigns the priorities to the DMA channels of DMAC based on mode of
operation.
First/Last Flip Flop (FF):
8257 have 8bit data line and 16 bit address line.8086 it is getting 8-bit data in
simultaneously.8086 cannot access 16-bit address in simultaneously.A0-A3 lines are used to
distinguish between registers, but they are not distinguishing lower and higher address. It is
reset by external RESET signal. It is also reset by whenever mode set register is loaded. So
program initialization with a dummy (00 H).
i. FF=1=Higher byte of address
ii. FF=0=Lower byte of address.
Design a microprocessor system to control traffic lights. The traffic light arrangement is
as shown in Fig. 3.25.
Fig. 3.26 The interfacing diagram for traffic light control system
I/O
Ma
p
Table: 3.10 Ports/Control Register and address lines
Software:
Source program:
Seven-Segment display
Seven segment displays are generally used as numerical indicators
It consists of a number of LEDs arranged in seven segments shown in the
Fig. 3.27.
Fig: 3.31 Circuit for driving single seven segment LED display
The value of the resistor in series with the segment can be calculated as follows:
Vcc — drop across LED segment — IR = O.
Drop across LED segment is nearly 1.5 V.
IR = Vcc. - 1.5 V
= 5 — 1.5 V
= 3.5 V
Each LED segment requires a current of between 5 and 30 mA to light.
Let‘s assume that current through LED segment is 15 mA and R=35V/15mA = 233ohm
The voltage drop across the LED and the output of 7447 are not exactly predictable.
A standard value 220 Q can be used.
The static display circuits work well for driving just one or two LED digits.
When there is more number of digits, the first problem is power consumption.
For worst-case calculations, assume that all eight digits with all segments are lit.
Therefore, worst case current required is
I = 8 (digits) x 7 (segment) x 15 mA (current per segment)
=84OmA
A second problem of the static approach is that each display digit requires a separate
BCD to 7 segment decoder.
Multiplexed Display
To solve the problems of the static display approach, multiplexed display method is
used.
Fig. 3.32 shows the 4 seven segment displays connected using multiplexed method.
Here, common anode seven segment LEDs are used.
Fig: 3.32 Seven segment display in multiplexed connection
Anodes are connected to +5V through transistor, Cathodes of all seven segments are
connected in parallel and then to the output of 7447 IC through resistors.
The same number only if all the digits are turned on at the same time.
The PNP transistors connected in series with the common anode of each digit act as an
ON and OFF switch for that digit. Here‘s how the multiplexing process works.
The BCD code for digit 1 is first output from port A, to the 7447.
The 7447, B to seven segment decoder outputs the corresponding seven segment code
on the segment bus lines.
The transistor Q connected to digit 1 is then turned on by outputting a low to that bit of
port B.
All of the rest of the bits of port B are made high.
The BCD code for digit 2 is then output to the port A, and bit pattern to turn on digit 2 is
output on port B.
After 2ms, digit 2 is turned off and the process is repeated for digit 3 and digit 4.
After completion of turn for each digit, the entire digits arc lit again in turn In multiplexed
display, the segment current is kept in between 40 mA to 60 mA.
Fig. 3.34 shows the circuit for driving LCD seven segment display using IC 4543B.
Fig.3.35 Circuit for driving LCD seven segment display using 4543B
The Fig. 3.35 shows how above circuit can be used to drive a 4-digit no multiplexed, 7-
segment LCD display.
BCO input for each display is latched in the corresponding latch.
LCD Modules allow display of characters as well as numbers. They are available in 16 x
2, 20 x 1, 20 x 2, 20 x 4 and 40 x 2 sizes.
The first figure represents number of character in each line and second figure represents
number of lines the display has.
The module has 14-pins.The function of each pin is given in the table 8.9.
The Fig. 3.36 shows the interfacing of a 20 character x 2-line LCD module with the
8051. As shown in the Fig. 3.37, the data lines are connected to the port I of 8051 and control
lines RS, R/V and E are driven by 3.2, 3.3 and 3.1 lines of port 3, respectively.
The voltage at VEE pin is adjusted by a potentiometer to adjust the contrast of the LCD.
For interfacing keyboard to the microprocessor based systems, usually push button
keys are used. These push button keys when pressed. Bounces a few times, closing and
opening the contacts before providing a steady reading, as shown in the Fig. 3.37 Reading
taken during bouncing period may be faulty. Therefore, microprocessor must wait until the key
reach to a steady state; this is known as key de bounce.
Fig. 3.38 shows the circuit diagram of key debounce. It consists of flip flop. The output
of flip-flop shown in Fig. 3.38 is logic t when key is at position. A (unpressed) and it is logic 0
when key is t position B
Fig: 3.38 Circuit diagram of key debounce
Fig. 3.43 shows sixteen keys arranged in four rows and four columns.
When keys are open row and column do not have any connection, when a key is
pressed.
It shorts corresponding one row and one column.
This matrix keyboard requires eight lines to make all the connections instead of the
sixteen hours required if the keys are connected individually, as shown in Fig. 3.41
Fig. 3.42 shows the interfacing of matrix keyboard.
It requires two ports:
1. an input port
2. An output port.
Rows are connected to the input port referred to as returned lines, and columns are
connected to the output port referred to as scan lines.
When all keys are open row and column do not have any connection. When any key is
pressed it shorts corresponding row and column.
If the output line of this column is low, it makes corresponding row line low; otherwise
the status of row line is high.
The key is identified by data sent on the output port and input code received from the
input port. The following section explains the steps required to identify pressed key.
D7 D6 D5 D4 D3 D2 D1 D0
1 1 COUNT STATUS CNT2 CNT1 CNT0 0
17. What is the purpose of control word written to control register in 8255?
(/May/June’13)
The control words written to control register specify an I/O function for each I.O port. The
bit D7 of the control word determines either the I/O function of the BSR function.
*****
12 Marks Questions
1. Draw the block diagram of 8279 keyboard/ Display controller and explain how to interface
the Hex Key pad and 7- segment LEDs using 8279.
2. Draw the functional block diagram of 8254 timer and explain the different modes of
operation.
3. Draw the block diagram of 8259A and explain how to program 8259A.
4. Explain the data transfer on a parallel printer interface using a timing diagram
5. Explain the interfacing of 4 X 4 matrix keyboard to the 8051 microcontroller with neat
diagram
6. What are the signals a microprocessor should have to support DMA? List and explain the
sequence of operations carried out during a DMA transfer.
7. Explain the four modes of keyboard operation in 8279.
8. Draw the architectural block diagram of 8259 Programmable interrupt controller and
Explain.
9. Explain the parallel communication interface with microprocessor
10. Explain the (i) modes of operation of timer and (ii) operation of interrupt controller