Sunteți pe pagina 1din 11

Delay Routine

● Delay routines are the subroutines used for maintaining the timings of
various operations in a microprocessor.
● In control applications certain equipment need to be ON/OFF after a
specified time delay.In such situation simple time delay routines can be
used to maintain the timings of the operation.
● A delay suroutine is generaly written as subroutine.(It can even be a
part of the main program).
● In a delay routine a count is set in a register of processor. Then it is
decremented by one till the content is zero.
● Zero flag will set when the content becomes zero
● When it is zero the time delay is over and the control is transferred to
the main program to carryout the desired operation
● The delay time is the total time taken to execute the delay routine
● It can be computed by multiplying the total number of T states to
execute the subroutine and the time for one T state of the processor.
● Total T states can be computed from the knowledge of the T states
required for each instruction
● Crystal oscillator will provide frequency microprocessor.
● For example, if the 8085 microprocessor has 6 MHz quartz crystal then,
The internal clock frequency =6 / 2 =3 MHz
Time for one T-state= 1 / 3 x 106= 0.33 µsec •
● There are three methods to introduce delays
(1) by using 8 bit register
(2) by using 16 bit register pair
(3) by using nested loop
● For small time delays (< 0.5 msec) an 8- bit register can be used.
For large time delays (< 0.5 Sec) l6-bit register should be used.
For very large time delays (> 0.5 sec), a delay routine can be repeatedly
called in the main program.
● The disadvantage in delay routines is that the processor time is wasted.
Delay subroutine using one register
MVI B,10H ; to generate delay a few registers of the microprocessor are
loaded with desired numbers
L1 DCR B ; decrment the content of reg B to zero
JNZ L1
RET

● To generate small delay one reister canbe used.


● After executing this program it will returns to main program

Instructions Staes
MVI B, 10H 7
DCR B 4
JNZ 10/7
RET 10
● Instruction JNZ takes 10 states when the content of register B is not zero
● When the content of B=0 it takes only 7 T states and the program returns to
RET instruction.

Instruction How many times the Total T states
● instruction is
executed

MVI B, 10H 1 7x1

DCR B 16 (it is the decimal value of 4x16


10 H)

JNZ 16 10x15+7x1

RET 1 10x1
● Total T states=7x1+4x16+(10x15+7x1)+10x1=238
● External crystal frequency=6MHz
● Internal clock frequency=External crystal frequency/2=3MHz
● One T state= time period of clock signal=0.33 microseconds
● Delay time= 238x0.33x10-6 =0.078 millisec
● To generate maximum delay reg B is loaded with FF (255 decimal)
The maximum delay ={7x1+4x255+(10x254+7x1)+10x1}x0.33 micro second
Delay subroutine using register pairs
LXI D,N : Count in the register D is N
L1 DCX D ; decrement count
MOV A,D ;Move the content of register D to A
ORA E
JNZ L1
RET
Instruction How many times the Total T states
instruction is executed
LXI D, N 1 1x10
DCX D N 6N
MOV A,D N 4N
ORA E N 4N
JNZ N (N-1)x10+ 1x7

RET 1 10
● Total number of T states= 24 N+17
● Delay=(24N+17)xtime for one T state (while calculating delay N should be
in decimal)
● Maximum delay occurs when count N=FFFFH
By using nested loop/using two registers
Instruction How many times the Total T states
instruction is executed
MVI B,N1 H 1 7x1

L1 MVI C,N2 H N1 times(N1 in decimal) 7xN1

L2 DCR C N1xN2 times (both are in 4xN1xN2


decimal)

JNZ L2 N1xN2 times (both are in decimal) 10x(N2-1)xN1+ 7x1xN1

DCR B N1 times 4xN1

JNZ L1 N1 times 10x(N1-1)+7x1

RET 1 1x10
Write a delay routine to produce a time delay of
0.5msec in 8085 processor based system whose clock
source is 6MHz quartz crystal?
Instruction How many times the Total T states
instruction is
executed
MVI B,NH 1 7

L1 DCR B N times (decimal) 4xN

JNZ L1 N times (N-1)x10+1x7

RET 1 1x10
● Total T states required=14N+14
● External crystal frequency=6MHz
● Internal clock frequency=External crystal frequency/2=3MHz
● One T state= time period of clock signal=0.33 microseconds
● Total delay=[14N+14]x0.33 microsec
● Given than delay=0.5 msec
● [14N+14]x0.33 microsec=0.5 msec
N = 10710 = 6BH
Crystal frequency and microprocessor frequency
● Crystal oscillator is connected between the
terminals to provide crystal frequency.
● Crystal frequency is used for
synchronisation for data transfer between
mupi and memory as well IO devices
● Crystal frequency=6 M Hz
● Microprocessor frequency= crystal
frequency/2

S-ar putea să vă placă și