2 Write a DELAY Subroutine that takes about 0004 seconds to
2. Write a DELAY Subroutine that takes about 0.004 seconds to execute. Include the algebraic expression for this delay routine, and show all calculations for how you determined your delay counter values. (a two-loop routine should be sufficient)
Solution
You havent mentioned for any processor name. So I am giving for 8085
Assume clock frequency = 3MHz
Clock period = 0.333us
Required T states = 0.004s/0.333us = 12012. The value of count is high so we take register pair BC
CODE :
LXI B , COUNT ; 10T lower address in B and higher address in C
LOOP DCX B ;6T
MOV A,B ; 4T move lower address in A
ORA C ;4T check if both A and C are zero
JNZ LOOP ;10/7T
RET ; 10T
Time delay = 10 + COUNT X (6+4+4+10) -3 + 10 = 12012
24COUNT = 12012 - 17 = 11995
COUNT = 500 dec = 01F4 H
NOTE : -3 in counting Time delay is because when JNZ executes in loop it has 10T states but if it fails , it has 7T states , so we have to remove 10 and add 7 since it executed inside loop.
