Active Learning Assignment FOR The Subject "Microprocessor & Interfacing"
Active Learning Assignment FOR The Subject "Microprocessor & Interfacing"
Active Learning Assignment FOR The Subject "Microprocessor & Interfacing"
ASSIGNMENT
FOR
THE SUBJECT
“MICROPROCESSOR &
INTERFACING”
Counters & Time Delays
PREPARED BY:
HEMANT H. CHETWANI
(130410107010 – TY CE-II)
What are Counters &
Time Delays ?
For example,
“MVI” instruction uses 7 T-States.
Therefore, if the Microprocessor is running at 2 MHz,
the instruction would require 3.5 mS to complete.
We can design Time Delay
using following three
Techniques:
The first instruction initializes the loop counter and is executed only
once requiring only 7 T-States.
The following two instructions form a loop that requires 14 T-States to
execute and is repeated 255 times until C becomes 0.
Using One Register
We need to keep in mind though that in the last iteration of the loop,
the JNZ instruction will fail and require only 7 T-States rather than the
10.
Therefore, we must deduct 3 T-States from the total delay to get an
accurate delay calculation.
To calculate the delay, we use the following formula:
Tdelay = TO + TL
Tdelay = total delay
TO = delay outside the loop
TL = delay of the loop
A minor problem arises in how to test for the final count since
DCX and INX do not modify the flags.
However, if the loop is looking for when the count becomes
zero, we can use a small trick by ORing the two registers in the
pair and then checking the zero flag.
Using a Register Pair
TO = 10 T-States
(The delay for the LXI instruction)
Body of loop 2
Nested loops can be
Initialize loop 1
easily setup in
Body of loop 1
Assembly language by
Update the count1 using two registers for
Is this
the two loop counters
No
Final
Count?
and updating the right
Yes
register in the right
Update the count 2 loop.
No Is this
Final
Count?
Yes
TO1 = 7 T-States
(MVI C, FFH instruction)
TL1 = (255 X 14) - 3 = 3567 T-States
(14 T-States for the DCR C and JNZ instructions repeated 255
times (FF16 = 25510) minus 3 for the final JNZ.)
TLOOP1 = 7 + 3567 = 3574 T-States
Using a Loop with in a Loop
Total Delay
TDelay = 57412 X 0.5 mSec = 28.706 mSec
Increasing the Time Delay
The Delay can be further increased by using
register pairs for each of the loop counters in
the nested loops setup.
Initialize Counter
Load Delay Register
Display
Body of loop
Time Delay
Update Count
Is this
Final
Is Count?
No Count No
Complete?
Yes
Yes
Initialize Counter
Initialize Counter
Display Count
Is No
No Count Time Delay
Complete?
Go back
Yes
End
End
MVI B,00H
NEXT: DCR B
MVI C,COUNT
DELAY:DCR C
JNZ DELAY
MOV A,B
OUT PORT#
JMP NEXT
Time Delay Calculation
Delay loop includes two instructions: DCR C and
JNZ with 14 T-states. Therefore the time delay TL in
the loop (without accounting for the fact that JNZ
requires 7 T-States in the last cycle, because count
will remain same even if the calculations take into
account the difference of 3 T-States) is:
A 10101010
After RLC 01010101
A AND 01H 00000001