Professional Documents
Culture Documents
& APPLICATIONS
Structure
19.1 Introduction
-- a e c t i v e ~ --
.
19.2 Memory Map '
19.3 Memory Interface Design
19.3.1 Memory Address Decoding
19.3.2 Partial Decoding
19.3.3 Bus Contention and Wait States
19.4 Input/OutputPorts
19.4.1 U 0 Device Select Pulses
19.4.2 U 0 Interface Design
19.4.3 Memory Mapped 110
19.5 Additional 110 Techniques
19.5.1 Interrupts
19.5.2 Serial UO
19.5.3 Direct Memory Access
19.6 Microprocessor Applications
'
19.1 INTRODUCTION
Although the microprocessor is very powerful and can carry out many functions, in order
for it to be useful, it has to be built into a system, such as a microcomputer, along with other
peripherals such as memory and inputloutput units. The technique of connecting these
peripherals to the microprocessor is called interfacing. Interfacing peripherals to the
microprocessor has to be studied in de@l because it is not simply connecting these devices
to the microprocessor pins that is involved. We have studied in Unit 17 that the
microprocessor has only one set of address and data lines to be used by all the peripherals.
This means that interfacing technique should include some sort of a scheme to select the
peripheral device that is required to communicate with the microprocessor while at the same
time isolating all other peripherals, even though all the peripheralsstay connected to the
microprocessor all the time.
Being versatile and programmable, microprocessors can be put to use in a variety of
applications. The basic hardware i$ the same for all the applications. The input and output
devices may, however, be different in each case based on the application needs. Different
programmes are written for different applications and loaded into the program memory for
execution by the microprocessor. In this Unit, we will discuss the issues involved in the
design of a microprocessor based systems and study a typical application as an example.
Objectives
After a study of this unit, you should be able to
explain the concepts of memory map, partial decoding, bus contention and wait
states as applied to a dcroprocessor system,
design memory and inputloutput systems for the 8085 microprocessor,
understand advanced topics in inputloutput &sign such as interrupts, serial
inputloutput and Direct Memory Access, and
define and formulate applications of the 8085 microprocessor.
I 256 bytes
I
64K bytes
Note that all memory addresses are expressed as hexadecimal numbers. 'Ihe maximum
possible size of 64 K has the address range from OOOOH to FFFFH.The 2 K ROM occupies
the address range 0000 to 07FFH.256 bytes of RAM occupy the address space from 2 0 0 0 ~
to 20FFH.
Example 19.1
Find the ending address of an 8 K-byte memory if the starting address is '0'
Solution
8 K-bytes = 8192 bytes
Starting address is 0. Ending address is 8191
010= qi ;819110= lFFFH.The address range is OOOOH to lFFFH.
Example 19.2
What is the ending address of a 2 K-bytes memory whose starting address is 300@3?
Solution
2 K-bytes = 2048 bytes = 8% bytes
Ending address is 3 m H+ 8% - 1 = 37FFH
19.3 MEMORY INTERFACE DESIGN
Designing a memory interface for a microprocessor consists of the following steps: We fnst
decide the size of the memory required and the address range it should occupy (memory
map). We then choose the type of the memory &vice to be used based on cost and other
conditions such as speed, availability etc. Based on this information, we now know how
many chips of the chosen &vice are needed to give the required memory size. Then, we
&sign the circuitry that will enable the memory to communicate with the CPU whenever
the CPU initiates either a read or a write cycle, and disables it at other times. If the memory
consists of more than one chip, only the appropriate chip or chips should be enabled.
Occasionally, the design has to be -ed to take into account the timing considerations,
i.e., the memory should respond to the CPU neither too quickly nor too late.
i
19.3.1 Memory Address Decoding Miemproemr Interfacing
&Applieatiom
Memory address decoding circuit utilises the address lines of the microprocessor to generate
the signals that enable the appropriate memory chips as required. The chip select function of
the memory device is used for this purpose, as mentioned in Unit 16. The decoding circuit
may use either a decoder or gates or a combination of both.
Let us assume that we want to design a memory circuit of size 2 K-bytes of RAM to be
interfaced to an 8085 microprocessor. Let us choose the address for this memory from
OOOOH to 07FFH.Let us assume that we have a single memory~hipof size 2 K-bytes at our
disposal. To address 2 K-bytes, we need 11 address lines. Of the 16 address lines A. to A15
of the 8085, we will use the lines A. to Alo for this purpose. This will give all the address
combinations from OOOH to 7FFHand we will be able to access any of the locations in the 2
K-byte RAM. However, we should not leave the five higher address lines All to AI5
unused. These lines should all be 0s in order to uniquely define the address range OH to
07FFH.For any other combination of values on these lines, other address ranges in the
overall 64 K memory may be selected. The operation of utilising these higher address lines
to uniquely enable only the required memory address and exclude other addresses is called
memory decoding and the circuit which does this is called the memory decoding circuit
Figure 19.2 shows the memory decoding circuit for this example. Notice that a
goes low
(and thus enables the memory) only when the lines A l l to A15 are all 0s. That is, this circuit
7 2 K bytes RAM
Figure 19.2 : (a) A 2 K-byte RAM circuit for 8085 microprocessor, (b) Memory map
rn --3- MEMR -
0E
Figure 19.3 : (a) Circuit of the 4 K-byte RAM for 8085 (b)Memory map
The two examples we have seen so far have both used a single chip in the design.
Sometimes, we may not get a single chip large enough to cover the entire memory range we
want to have. In such a case asignal should be generated separately for each chip. The
required memory range is partitioned into subranges and each of the chips is enabled for the
appropriate subrange. Let us understand this concept by means of an example.
Example 19;4
Design a memory system of size 8 K-bytes to interface with the 8085
microprocessor. Start with the address OOOOH.Assume that you have to use four
pieces of 2 K-bytes RAM.
Solution
8 K-bytes = 819210bytes = 20% bytes
If the starting address is O H ,ending address is lFFFH.
Each RAM has 2 K-bytes of memory. We can divide the total range into four
subranges as follows: ,
IFFF H
Chip #4
1800
17FF
Chip #3
1000
OFFF
Chip #2
0800
07FF
Chip # I
0000~
(a)
Figure 19.4 (a) : 8 K - byte RAM interface to 8085 microprocessor (b) Memory map
Out of a total of 13 bits required to address 8 K memory, 11 bits are needed by each
chip to select one of 2 K address locations contained in it. The remaining two bits
will then be used to select one of the four chips to address the required subrange.
Figure 19.4 shows the circuit. Note that the address lines A l and A12 are decoded
into four chips. Each output corresponds to a combination of A l 1 and A12 as required
to address one of the subranges as given below:
A12 A1 1 Subrange
0 0 0000 - 07FF
0 1 0800 - OFFF
1 0 1000 - 17FF
1 1 1800 - 1FFF
The three remaining address lines A13,A14 and A15 are required to be all low to
address the total range properly. The three-input OR gate ensures that only if they all
are low, the address decoder will be enabled thereby enabling the memory circuit.
For any other combination of A13,,414, A15 (which means that the address is outside
the required range of 0000 - 1FFF), the memory circuit is totally disabled.
SAQ 1
Using the required number of 1 K x 4 bits RAM, design a memory circuit of size 2
K-bytes with the starting address 7 0 0 0 ~
to interface with the 8085.
A14- used
Figure 19.5 : A partially decoded memary system (a) Circuit (b) Memary map
A12 to A15 are all 0s. This is not a restrictionFor any other combination of these address
lines also, the same two memory chips will be acCessed because these lines are not used and
only the adddss lines A. to A l 1 will be used for address decoding of the memory. For
example, if the address ranges are from FOOO to F7FF and F800 to FBFF, still the same two
memory chips will be accessed by the circuit.
Example 19.5
Find the range of addresses for the memory chip in the circuit shown in Figure 19.6.
A13 -v
Rgure 19.6 :The partially deeded memory system for Example 19.5
Solution
The size of memory in the chip is 1 K byte since it uses 10 address lines plus 8 data
lines. 1 K locations have addresses in the range OOOOH to 03FFH.In order to find the
actual address of the memory in this circuit, we have to consider A13,Al4. A15which
are all 1. Since A12. All and Alo are not used, we can assume them to be 0s. The
addresses are therefore
00 0000 0000
Ill000 { ) which trimlate to E O H
This range was arrived at with the assumption thatAI2,All andAloare 0s. For other
combinations, we will get different ranges, but they are all equivalent (as far as this
circuit is concerned) since they will all represent the addresses in the same memory
device. For example, the combination 100 for A12,All, A10will give the address
range from FOOOHto F3FFH.
19.3.3 Bus Contention and Wait States
Memory devices take time to respond. After an address is placed on its address lines and the
memory is enabled, the memory takes time to internally decode the address and become
ready either to place the requested data on the data lines (in the case of read cycle) or to read
the data placed on the data lines for storage (in the case of a write cycle). This time delay is
called the memory access time and is made up of several delay components. Furthermore,
the access times are different for read and write operations. We shall not be going into the
details of how these delay times come about, but only say that when we use a memory
device in a microprocessor system, we have to make sure that there is a match between the
speed requirements of the microprocessor as given by its read and write cycle times and the
access time specificationsof the memory device.
With the present day technology, memory devices are made extremely fast and they are
available in a wide range of sizes, speeds and cost. Especially for a rather slow
microprocessor such as 8085, there should be no difficulty in identifying memory devices
with the required specifications. However, it may be of interest to learn about two problems
related to timing that are likely to arise in a memory interface design. Again, in the design of
a simple 8085 system, we can avoid these problems by choosing proper memory devices,
but it is worthwhile to know about these anyway.
Bus contention
A bus contention occurs when two devices try to use a bus at the same time. In the case of
8085 microprocessor, we h o w that the same set of eight lines are used as lower byte
address lines A. to A7 as well as the data lines Do to D7. Signal ALE is used to define the
function of these lines at any given time. When ALE is high, these lines are used as low
order address bus. Refer to Figure 19.7.
T1 T2 T3
CLK
Memory Address
.Do AD%
-}- -- - ----- D a t a from memory -
UO decoding is similar to memory decoding in the sense that the address lines (in this case Miemp~oc~gs~r
rntel(a
Ao-A7)are used to select the port just as address lines AGls are used to select the memory &~ p p l i i
location. However, there is a difference. In memory design, a single decoder circuit decodes
a range of memory addressks since memory chips contain a large number of address
locations. On the other hand, I10 &coding has to be done for individual devices since these
are independent of each other and each has its own address. The second difference : I/0
decoding circuit uses the address of the device, or signals (depending on whether it
is an input or an output port) and the I O signal
~ (which will be high when CPU performs
an I10 operation as against low for memory operatidn) and comes out with a signal called
device select pulse. This pulse is used to select (or enable) the I10 port required to
communicate with the CPU. Since each device ,is identified with a decoding circuit and an
associated device select pulse, only the device of choice will be enabled and all others will
be disabled at that time. Figure 19.9 explains this feature.
OUTPUT DEVICE
SELECT PULSE
( t o enable (to enable
i n p u t port) output port)
(a) (b)
Figure 19.9 : Device select pulse generation (a) for input port (b)for output port
74LS244
OUT IN
to D o 0 0 0 (from S1)
h
tom or
INPUT PORT
I Y \
From
74 LS 373
IN OUT
. I
I
I
I
From I I
8085
.
d a t a bus
. j
7
CLK
select pulse
from t h e
decoded circuit
Output device
select pulse
t o port
Figure 19.12 (a) Output device (b) Output $c(c) Output decoding circuit
SAQ 2
Design an output port with port address 80H to interface a pair of BCD displays to an
8085 microprocessor.
RESET IN :
RST6.5 :
will generate RESET signal and force program counter to 0000; connected
external hardware to initiate program. (Pin 36 of 8085)
vectored interrupt ; connected to applications hardware, vector
location is 0034~.
I
The eight datafaddresslines (ADo-AD7)are bused between three devices. They are used to
transmit the 8 data bits and the 8 low order address bits between the processor and the
memory devices. Address lines AS-Aloare connected between the 8085 and 8755. Since the f
8156 RAM possesses only 256 bytes of memory (as opposed to 8755), it does not require
these additional address bits. I
RAM (8156) and ROM (8755) are mapped by address bit All. The 8755's ROM program I
I
resides in memory location OOOOH - 07FFH(the extent of its 2-K byte memory), and the chip i
is selected when All is LOW. Hence, the A1 1 line is connected to the pin of the 8755. In i
contrast, the 8156 RAM chip is selected when All is HIGH, thus giving it the memory range
0 8 0 0 ~- 08FFH(256 bytes).
Output portsA and B of the 8156 interface to the external hardware. Port B is designated as
an output from 8085 and issues control bits to the conversion hardware. Port A is designated
as an input and receives the &bit data word from the AID converter.
I10 is performed by standard I10 techniques. When executing an IN or OUT instruction, the
8085 deselects memory and selects I10 ports by bringing I O HIGH ~ and transmitting the
8-bit port address on address lines ADo-A@ and AS - AI5. Since the 8156 is enabled when
All is HIGH, the software designer must be certain to enable that bit in the port address.
On the 8156 chip, bits ADo - AD7 control the specific port accessed.
0 0 0 Command/status register
0 0 1 Port A
0 1 0 Port B .
Commandstatus register is a register which is pat ofill1 the programmable I10 chips. It is
an additional port accessible to the microprocessor. By programming this register, we get
different configurations for the I10 ports in the chip. (For example, in this application,Port
A acts as input and Port B acts as an output port).
Address bitAll translates to address bitAD3 in the port address. Therefore,AD3 will be
HIGH for all 8 156 I10 port addresses:
Micmpmeaaor Interfacing
Port Address AD3 AD2 AD1 ADO & Applidom
08~ 1 0 0 0 Command1
status register
09~ 1 0 0 1 Port A
OAH 1 0 1 0 Port B
Four 7-segment displays are used to display the results, two each for the peak and rms
values. The same port (port A of the 8755 chip) is used to activate all the four displays in
turn. Each 7- segment display requires four bits of data. When a digit is to be outputted, the
lower four bits are used for data and the upper four bits to enable one of the four displays.
Each display has its own latchhexadecimal 7-segment decoder combination (9356). When
one of the bits of the upper four bits is enabled, the corresponding latchldecoder latches the
lower four bits which is meant to be the data for that particular digit. The bits are decoded
into the 7-segment display information and is used to light up the corresponding segments
of the display. The process is repeated for each digit in turn.
Each bit of the 8755 port A must be defined as an output by a Data Direction Register
(DDRA). Also, writing into either port A or DDRA rcquires that the 8755 device be
enabled. Therefore, A , (corresponding to AD3 in an OUT operation) must be LOW. The
rcsulting port addresses for the 8755 are :
0 0 0 0 Oh Port A
0 0 1 0 O ~ H DDRA
Besidcs the three Intel deviccs, the microcomputer includes a 1 MHz crystal oscillator to
provide a master clock, a RESET switch to reset the system, and latched LED displays to
output the peak and rms values.
AID Conversion Hardware
The circuitry is composed of three circuits: absolute value, sample and hold, and A/D
converter.
The absolute value circuit used rectifies the input voltage within the feedback loop of an
operational amplifier (see Figure 19.14). When the input voltage e l becomes negative, the
output of operational amplifier 1 becomes positive by one diode drop and turns off thc
upper diode. No effective current flows from operational amplifier 1, and the output voltage
of operational amplifier 2 is - e l = abs(el). When el becomes positive, the lower diode is
turned off, and the output of operational amplifier 1 becomes (-el - 0.7 V). The output of
operational amplifier 2 then becomes (-(-2el + el)) = el. In either case, the output voltage
of operational amplifier 2 is the absolute value of the input wave, and no diode drop error is
introduced. This is a variation of the precision rectifier circuit which you studied in Unit 13.
After the input voltage is rectified, it is sampled by the sample and hold circuit. A SAMPLE
signal of 650 ps duration is transmitted from 110 port B of the 8156 and inverted by a 4049
CMOS buffer. When SAMPLE is HIGH, the output of the buffer is LOW, and the 2N2222
transistor is turned off. Sirice it is not conducting, its collector voltage remains at 15 V, and
the 4066 analog switch is closed. T o open the switch, SAMPLE is set LOW, the 2N2222
transistor saturates, and the gate voltageof the analog switch is effectively set to 0 V. When
this analog switch is closed, a capacitor charges to sample voltage.
Finally, the sampled and rectified voltage is converted to an 8- bit digital word by the 8703
AID converter. The 8703 is biased to provide a 0-10 V scale range (i.e., OOH is equivalent to
0 V, FFII to 10 V). All signals to the 110 ports of the microcomputer are buffered through
4050's to isolate the expensive CMOS A/D converters.
The eighl digital output bits are connected to port A of the 8156 and are read during the
interrupt service routine. Conversion is begun by a programmed START CONVERSION
pulse transmitted from the 8085 through port B of the 8156. After the A/D converter has
completed conversion of the input voltage, the status line BUSY goes LOW. When enabled
by the software-controlled ENABLE bit, the inverted signal BUSY triggers the RST6.5
interrupt. and the interrupt service routine reads the valid data.
,
Since the BUSY output from the 8703 remains LOW (BUSY remains HIGH) between
conversions, a software latch must be used to prevent further interrupts. Therefore, BUSY is
ANDed with ENABLE to provide an RST6.5 interrupt only when the microcomputer is
ready to accept it. During the interrupt service routine, ENABLE is set LOW and remains in
that state until the next sample is taken and the next AID conversion begun. Figure 19.15
depicts the timing of the control signals.
Sample
' k1Ops
start
conversion
'i\
Hardware
Interrupt
ENABLE
I -i c - 1 5 ~ ~
A/D data
outputs
-v
,-my
I
I
I
I 1
BUSY -- I
\ I /
RST 6.5
Wait acknowledged
for
interrupt 1
1n*rupt
given
7 START
READ SAMPLING
PERIOD & No. OF
the 8755 so that the data will be present before
display registers are clocked. Once the data are
stable, the masked data are ORed with control
bits to clock the display registers. Four 9356
latch/decoders are used for the display.
The flow charts are given in Figures 19.16 to
19.19 and a listing of the programs follows.
pz
SAMPLINIG PERIOD
I1 AVERAGE= -TOTAL 1
' NUMBER
NUMBER
1 -
START
CT)
CHANGE HIGHER
NIBBLE TOO 0 0 0 1
i
MASK LOWER NIBBLE
OF BCD DATA
SHIFT BY 4BITS
HIGH BITS=0010
(7 START
HIGH BITS=0100
+
OF BCO DATA
SHIFT BY 4 BITS
FLAG =FFH
Figure 19.18 : Intempt Service Routine Figure 19.19 : Output Display Rautines
Note :LED displays l&2 m l a y maximum
magnitute in BCD. LED displays 3&4
display RMS value is BCD.
-
M i c m p ~ Interlacing
r
- Program code & Applications
LXI SP, 20C2H initialize stack pointer
CALL INPUT call subroutine to get
DELAY and NUMSAMPLE and
initialise MAX
MVI A, 02H
OUT 0 8 ~ 9 configure 8156
MVI A, OH
OUT OAH , clear all Port B signals
AGAIN: MVIA,OIH
OUT OAH , set pin PBo (sample) HIGH
CALL DLY 1 , Give delay of 650 p secs
MVI A, OOH
OUT OAH 9 make SAMPLE signal low
MVI A, 0 4 ~
OUT OAH t make START (of conversion) signal
high (Pin PB2)
CALL DLY2 Give delay of 10 ps
MVI A, OH
OUT OAH 9 bring START signal down
MVI A, 0 2 ~
OUT OAH 9 make Pin PB1 INT ENABLE
signal high
MVI B, O q r 9 B is a flag which gets altered in the
interrupt service routine
BACK : CMP B, OH
JZ BACK , wait for interrupt
LXI B, NUMSAMPLE
LDAX B , load B with contents of NUMSAMPLE
(total no. of sampleslperiod)
LXI H, COUNT
CMP M , check if count = tot.no. of samples
required
JZ OVER
CALL DLY3 , Give delay equal to sampling period
JMP AGAIN , if there are more samples to be read in,
jump back to start.
-
OVER : LXI B, TOTAL , To calculate average, we divide the
i LDAX B , sum of the magnitudes by number
MOV D, A 9 of samples (stored in mem locations
LXI B, NUMSAMPLE : TOTAL & NUMSAMPLE resply.)
-
LDAX B , -
CALL DIVIDE , DIVIDE subroutine takes in inputs from
LXI B ,AVERAGE , registers A and D and gives the quotient in
STAX B 9 A and the remainder in D
Answer is stored in AVERAGE
-
-
LXI B, SQTOTAL 9 To calculate rms, we calculate the
LDAX B , mean square and then take its
MOV D,A , square root; subroutine SQROOT
LXI B, NUMSAMPLE takes in accumulator value and
LDAX B 9 returns its root in A
CALL DIVIDE 9
CALL SQROOT
LXI B, RFvlS -
STAX B
CALL OUTPUT 9 output subroutine displays all results
RST
Interrupt Service Routine
PUSH PSW , store existing status
PUSH H
MVI A, 00H
OUT OAH , set ENABLE low
IN OgH , Read in data from AJD
r
MOV B,A
LXI H,MAX , compare data read in with the max
CMP M , stored in MAX; if the new data is
JC PROCEED , p i g h e r , update MAX
MOV M,A
PROCEED : LXI H, TOTAL
ADD M
MOV M,A , update the total
LXI H,COUNT , update the count
INC M
MOV A, B , update the mean square value
CALL SQUARE
LXI H, SQTOTAL
ADD M
MOV M,A
MVI B, FFH t set flag
RET return
DLY 1 : ' PUSHB ,
MVI C, 5gH 9
r
\
MOV A, B
RRC
RRC
RRC
RRC
A N I WH
OUT%
POP H
POP B
POP PSW
RET
Note:
- LED displays 1 & 2 display max value in BCD
- LED displays 3 & 4 display rms value in BCD
19.7, SUMMARY
In this Unit, we have learnt the techniques of interfacing peripherals such as memory and
inputloutput devices to the microprocessor. We have studied the various design steps in
memory and YO interfacing along with necessary circuitry. We were also introduced to
some advanced concepts in microprocessor interfacing such as Interrupts, Serial UO and
Direct Memory Access. Finally, we understood the issues involved in the design of
microprocessor based systems and studied a typical application example.
Each 1 K memory requires 10 bhs address and the total memory of 2 K requires 11
bits. That is, we will use address lines Ao-A9 for each deice to select one of the 1 K
locations and line Alo to select between the two subranges as shown below:
Subrange Ale
The remaining address lines A, 1 to AI5 should have the following values to select the
addresses given in the problem :
A15 A14 I 4 3 A12 All
0 1 1 1 0
They can be combined in a NAND gate to generate aselect signal which can then be
combined with the required level of Alo to form the CS signals for the two subranges.
Ao-o
MEMR
MEMw
10
' c Ao-e
MEMW
-I
CS
3
D0-3
4
Do-3
M
MEMR
~
-
W
A o-e
-I
CS
D0-3
-
4
D4-7
1Kx4 1Kx4
IN OUT
From D~~ r\ t o BCD
data bus
of -8085 displays
I
I
I
I