Unit Chapters
2
Indus University
2014
ROM
RAM
Input Buffer
Address
Lines
WR
CS
Output Buffer
Address
Lines
RD
CS
Output Buffer
RD
Data Lines
Date
Lines
AV / M&I
Indus University
2014
Interfacing Memory
Accessing memory can be summarized into
the following three steps:
Select the chip.
Identify the memory location.
Enable the appropriate read or write buffer.
Translating this to microprocessor domain:
The microprocessor places a 16-bit address on the
address bus.
Part
of the address bus will select the chip and the other
part will go through the address decoder to select the
register.
The
Chip Selection
Circuit
8085
CS
A15-A8
ALE
A9- A0
AD7-AD0
WR
RD
IO/M
Latch
A7 - A 0
1K Byte
Memory
Chip
D7- D0
RD
AV / M&I
Indus University
WR
2014
AV / M&I
Indus University
2014
AV / M&I
Indus University
2014
Memory Interfacing
AV / M&I
Indus University
2014
Address Decoding
The logic combination at address A15-A12
must have logic 0000 to activate the Chip
Enable,
and the address A11-A0 can have all logic
combinations either 0 or 1.
Therefore the range of address for this chip
A is
A 0000H
A A
A A0FFFH;
A A A A A A A A A A
until
15
14
0 0
0
0 0
0 0
13
12
Chip Enable
AV / M&I
11
10
0 0 0
01 01 01
1 1 1
0
1
0
1
0 0
1 1
0
1
0
1
Register Select
Indus University
2014
Address Range?
AV / M&I
Indus University
2014
Decoding Techniques
Absolute Decoding:
In absolute decoding address lines which are
not connected to the memory chip are used
to generate the Chip Enable (CE) signal.
Partial Decoding
In Partial Decoding all remaining address
lines which are not connected to the memory
chip may not be used to generate the Chip
Enable (CE) signal.
AV / M&I
Indus University
2014
RAM
RO
M
RO
M
RAM
Address Range ?
AV / M&I
Indus University
2014
Examples
Indus University
2014
Examples
Interface 2KB of RAM to 8085 Using (1K x 4)
chips , 74LS138(3 to 8 decoder) and full
address decoding.
AV / M&I
Indus University
2014
Partial Decoding
No Multiple Addresses
AV / M&I
Multiple Addresses
Indus University
2014
Interfacing I/O
AV / M&I
Indus University
2014
Indus University
2014
Indus University
2014
AV / M&I
Indus University
2014
Operan
Description
d
8-bit
This instruction transfers the data
Address from the accumulator to the output
device.
Op
code
IN
Operan
Description
d
8-bit
This instruction transfers the data
Address from
the
output
device
to
accumulator.
AV / M&I
Indus University
2014
AV / M&I
Indus University
2014
AV / M&I
Indus University
2014
Decoding Techniques
Absolute Decoding:
All address lines are used for generating
the device address.
Partial Decoding:
In partial decoding all the address lines are
not used for generating the device address.
AV / M&I
Indus University
2014
Partial Decoding
AV / M&I
Indus University
2014
Input Interface
AV / M&I
Indus University
2014
AV / M&I
Indus University
2014
Indus University
2014
AV / M&I
Indus University
2014
AV / M&I
Indus University
2014
AV / M&I
Indus University
2014
AV / M&I
Indus University
2014
D0
Bits: X
1
0
Segments NC G
:
A
AV / M&I
1
F
0
E
0
D
1
C
Indus University
1 = 66 H
B
2014
AV / M&I
Indus University
2014
AV / M&I
Indus University
2014
AV / M&I
Indus University
2014
AV / M&I
Indus University
2014
AV / M&I
Indus University
2014
Counters
A loop counter is set up by loading a register
with a certain value
Then using the DCR (to decrement) and INR
(to increment) the contents of the register
are updated.
A loop is set up with a conditional jump
instruction that loops back or not depending
on whether the count has reached the
termination count.
AV / M&I
Indus University
2014
Counters
The operation of a loop counter can be
described using the following flowchart.
Initialize
Body of loop
No
Is this
Final
Count?
Yes
AV / M&I
Indus University
2014
Delays
each instruction passes through different
combinations of Fetch, Memory Read, and
Memory Write cycles.
Knowing the combinations of cycles, one
can calculate how long such an instruction
would require to complete.
AV / M&I
Indus University
2014
Delays
Knowing how many T-States an instruction
requires, and keeping in mind that a T-State
is one clock cycle long, we can calculate the
time using the following formula:
Delay = No. of T-States / Frequency
For example a MVI instruction uses 7 TStates. Therefore, if the Microprocessor is
running at 2 MHz, the instruction would
require 3.5 Seconds to complete.
AV / M&I
Indus University
2014
Delay loops
We can use a loop to produce a certain
amount of time delay in a program.
The following is an example of a delay loop:
M VIC, FFH
7 T-States
LO O P D CR C 4 T-States
JN Z LO O P 10 T-States
Indus University
2014
Indus University
2014
AV / M&I
Indus University
2014
AV / M&I
Indus University
2014
AV / M&I
Indus University
2014
48
AV / M&I
Indus University
2014
Nested Loops
Nested loops can be
easily
setup
in
Assembly language by
using two registers for
the two loop counters
and updating the right
register in the right
loop.
In the figure, the
body of loop2 can
be before or after
loop1.
Initialize loop 2
Body of loop 2
Initialize loop 1
Body of loop 1
Update the count1
No
Is this
Final
Count?
Yes
Update the count 2
No
Is this
Final
Count?
Yes
AV / M&I
Indus University
2014
AV / M&I
Indus University
2014
Indus University
2014
Total Delay
TDelay = 57524 X 0.5 Sec = 28.762 mSec
AV / M&I
Indus University
2014
AV / M&I
Indus University
2014
Program
repeat:
MVI B,00H
7T
display:
OUT 80H
10T
10T
DCX H
6T
MOV A,L
4T
ORA H
4T
JNZ back
10T
INR B
4T
MOV A,B
4T
CPI 0FH
7T
JNZ display
10T
JZ repeat
10T
back:
AV / M&I
Indus University
2014
AV / M&I
Indus University
2014
MVI B, 00H
NEXT:
DCR B
MVI C, COUNT
DELAY: DCR C
JNZ DELAY
MOV A, B
OUT PORT
JMP NEXT
56
AV / M&I
Indus University
2014
57
AV / M&I
Indus University
2014
Example
Write a program to generate continuous
square wave with period of 500s. Assume
that system clock period is 325ns and use
bit D0 to output
the square wave.
500
s
After RLC
Remaining
contents
AV / M&I
Indus University
2014
Program
ROTATE:
DELAY:
AV / M&I
MVI D,AAH
MOV A,D
RLC
MOV D,A
ANI 01H
OUT Port address
MVI B,COUNT
DCR B
JNZ DELAY
JMP ROTATE
Indus University
2014
AV / M&I
Indus University
2014
Stack and
Subroutine
AV / M&I
Indus University
2014
The Stack
The stack is an area of memory identified
by the programmer for temporary storage
of information.
The stack is a LIFO structure.
Last In First Out.
AV / M&I
Indus University
2014
The Stack
Given that the stack grows backwards into memory, it
is customary to place the bottom of the stack at the
end of memory to keep it as far away from user
programs as possible.
In the 8085, the stack is defined by setting the SP
(Stack Pointer) register.
LXISP, FFFFH
Indus University
2014
AV / M&I
Indus University
2014
12
AV / M&I
F3
FFFD
SP
Indus University
2014
AV / M&I
Indus University
2014
AV / M&I
Indus University
2014
LIFO
The order of PUSHs and POPs must be opposite of
each other in order to retrieve information back into
its original location.
PU SH B
PU SH D
...
PO P D
PO P B
Indus University
2014
Indus University
2014
Subroutines
A subroutine is a group of instructions that will be
used repeatedly in different locations of the program.
Rather than repeat the same instructions several
In
Assembly
language,
subroutine
can
exist
it
is
customary
to
place
subroutines
Indus University
2014
Subroutines
AV / M&I
Indus University
2014
the
address
of
the
instruction
supplied
with
the
CALL
2000CALL 4000
2003
instruction.
PC
2003
FFFB
FFFC
FFFD
FFFE
FFFF
PC
AV / M&I
03
20
SP
4000
Indus University
2014
2003
FFFB
FFFC
FFFD
FFFE
FFFF
4014. . .
4015RET
AV / M&I
Indus University
03
20
SP
2014
Cautions
AV / M&I
Indus University
2014
and the subroutine retrieves the data from the location and
uses it.
AV / M&I
Indus University
2014
back
to
the
calling
program
upon
Indus University
2014
Indus University
2014
Indus University
2014
Lights
Data Bits
On time
1. Green
D0
15 seconds
2. Yellow
D2
5 seconds
3. Red
D4
20 seconds
4. Walk
D6
15 seconds
5. Dont walk
D7
25 seconds
The pedestrian should cross the road when the green light is on
AV / M&I
Indus University
2014
Time Sequence in
seconds
D
7
D6 D
5
D
4
D3 D
2
D
1
D
0
Hex
Cod
e
0 to 15 seconds
41H
15 to 20 Seconds
84H
20 to 40 Seconds
90H
80
AV / M&I
Indus University
2014
Program
LXI SP , 2000H
START:
MVI A, 41H
OUT PORT1
MVI B,15H
CALL DELAY
MVI A,84H
OUT PORT1
MVI B,05H
CALL DELAY
MVI A,90H
OUT PORT1
MVI B,14H
81
AV / M&I
CALL DELAY
Indus University
2014
PUSH D
PUSH PSW
SECOND:
LXI D, COUNT
LOOP:
DCX D
MOV A,D
ORA E
JNZ LOOP
DCR B
JNZ SECOND
POP PSW
POP D
RET
AV / M&I
Indus University
82
2014
RST Instruction
RST instructions are 1 byte call instructions
that transfers the program execution to a
specific location. They are executes same as
call instruction. These instructions are
generally used in conjunction with interrupt
process.
RST
0
CALL 0000H
RST 4
CALL
0020H
RST
1
CALL 0008H
RST 5
CALL
0028H
RST
2
CALL 0010H
RST 6
CALL
0030H
RST
3
CALL 0018H
RST 7
CALL
0038H
AV / M&I
Indus University
2014
CALL
2090H
Subroutine
1
203F
H
CALL
203FH
RET
AV / M&I
Subroutine
2
Indus University
RET
2014
2050H
RZ
2058H
RC
2070H
RET
AV / M&I
Indus University
2014