Delay Generation in 8085
Delay Generation in 8085
in 8085 Microprocessors
Kushal Roy (IIT Roorkee), Dept of ECE,
HIT Haldia
When the delay subroutine is executed, the
microprocessor does not execute other tasks. For
the delay we are using the instruction execution
times. executing some instructions in a loop, the
delay is generated. There are some methods of
generating delays. These methods are as follows.
3
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:
4
Delay loops
• We can use a loop to produce a certain amount of time delay
in a program.
• TO = 7 T-States
– Delay of the MVI instruction
8
Using a Register Pair as a Loop Counter
• The following is an example of a delay loop set
up with a register pair as the loop counter.
LXI B, 1000H 10 T-States
LOOP DCX B 6 T-States
MOV A, C 4 T-States
ORA B 4 T-States
JNZ LOOP 10 T-States
9
Using a Register Pair as a Loop Counter
• Using the same formula from before, we can
calculate:
• TO = 10 T-States
– The delay for the LXI instruction
No Is this
Final
Count?
Yes
11
Nested Loops for Delay
• Instead Register Pairs, a nested loop structure
can be used to increase the total delay
produced.
MVI B, 10H 7 T-States
LOOP2 MVI C, FFH 7 T-States
LOOP1 DCR C 4 T-States
JNZ LOOP1 10 T-States
DCR B 4 T-States
JNZ LOOP2 10 T-States
12
Delay Calculation of Nested Loops
• The calculation remains the same except that it the formula must be
applied recursively to each loop.
– Start with the inner loop, then plug that delay in the calculation of the
outer loop.
13
Delay Calculation of Nested Loops
• Delay of outer loop
– TO2 = 7 T-States
• MVI B, 10H instruction
– TL1 = (16 X (14 + 3574)) - 3 = 57405 T-States
• 14 T-States for the DCR B and JNZ instructions and 3574
T-States for loop1 repeated 16 times (1016 = 1610) minus 3 for the final JNZ.
– TDelay = 7 + 57405 = 57412 T-States
• Total Delay
– TDelay = 57412 X 0.5 mSec = 28.706 mSec
14
Increasing the delay
• The delay can be further increased by using
register pairs for each of the loop counters in
the nested loops setup.
• It can also be increased by adding dummy
instructions (like NOP) in the body of the loop.
15
Write a program to generate a delay of
0.25 sec if the crystal frequency is 5MHz