In this section we will see how to generate the time delay using 8085 programs. The delay will be used in different places to simulate clocks, or counters or some other area.
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.
Using NOP instructions
Using 8-bit register as counter
Using 16-bit register pair as counter.
Using NOT instructions:
One of the main usage of NOP instruction is in delay generation. The NOP instruction is taking four clock pulses to be fetching, decoding and executing. If the 8085 MPU is working on 6MHz clock frequency, then the internal clock frequency is 3MHz. So from that we can easily determine that each clock period is 1/3 of a microsecond. So the NOP will be executed in 1/3 * 4 = 1.333µs. If we use the entire memory with NOP instruction, then 64K NOP instructions will be executed. Then the overall delay will be 216 * 1.333µs = 87359.488µs, though the time is not so large and the program size is also large. So this type of NOP instruction can be used to generate a short time delay for few milliseconds.
Using 8-bit register as counter:
Counter is another approach to generate a time delay. In this case the program size is smaller. So in this approach we can generate more time delay in less space. The following program will demonstrate the time delay using 8-bit counter.
MVI B,FFH LOOP: DCR B JNZ LOOP RET
Here the first instruction will be executed once, it will take 7 T-states. DCR C instruction takes 4 T-states. This will be executed 255 (FF) times. The JNZ instruction takes 10 T-states when it jumps (It jumps 254 times), otherwise it will take 7 T-States. And the RET instruction takes 10 T-States.
7 + ((4*255) + (10*254)) + 7 + 10 = 3584. So the time delay will be 3584 * 1/3µs = 1194.66µs. So when we need some small delay, then we can use this technique with some other values in the place of FF.
This technique can also be done using some nested loops to get larger delays. The following code is showing how we can get some delay with one loop into some other loops.
MVI B,FFH L1: MVI C,FFH L2: DCR C JNZ L2 DCR B JNZ L1 RET
From this block, if we calculate the delay, it will be nearly 305µs delay. It extends the time of delay.
Using 16-bit register-pair as counter:
Instead of using 8-bit counter, we can do that kind of task using 16-bit register pair. Using this method more time delay can be generated. This method can be used to get more than 0.5 seconds delay. Let us see and example.
|Program||Time (T-States) |
| LXI B,FFFFH|
LOOP: DCX B
10 (For Jump), 7(Skip)
In the above table we have placed the T-States. From that table, if we calculate the time delay, it will be like this:
10 + (6 + 4 + 4 + 10) * 65535H – 3 + 10 = 17 + 24 * 65535H = 1572857. So the time delay will be 1572857 * 1/3µs = 0.52428s. Here we are getting nearly 0.5s delay.
In different program, we need 1s delay. For that case, this program can be executed twice. We can call the Delay subroutine twice or use another outer loop for two-time execution.