LAB 7 Delay Calculation Using Loops
LAB 7 Delay Calculation Using Loops
DELAY CALCULATIONS
USING LOOPS
CLOCK CYCLE VS MACHINE CYCLE
To execute instruction, CPU takes certain number of
machine cycles. In 8051, one machine cycle is equal to
12 clock cycles.
1
1+(2 * 200)
1+(2 * 200) +1
(1+(2 * 200) + 1)*1.085 = 436.17 µ Sec
NESTED LOOPS- DELAY
ORG 00H
MOV P0, #0 ; Initialize port 0 and accumulator
MOV A, #0
START:
INC A ; Increment A
MOV P0, A ; Send contents of A to port 0
DELAY:
MOV R0, #255 ; initialize R0 and R1 with 255
LOOP1:
MOV R1, #255
LOOP2:
DJNZ R1, LOOP2 ; decrement R1 and jump loop2 if
; not zero
DJNZ R0, LOOP1 ; decrement R0 and jump loop1 if
; not zero
JMP START
END ; Delay = ?
DELAY CALCULATION
DELAY:
MOV R0, #255 ; 1mc instruction
LOOP1:
MOV R1, #255 ; 1mc instruction
LOOP2:
DJNZ R1, LOOP2 ; 2mc instruction
1
1+1*255
1+1*255 +2*255*255
1+1*255 +2*255*255+2*255
(1+1*255 +2*255*255+2*255)*1.085 = 141,935.36 µ Sec
141,935.36 µ Sec = 141.96 mSec
NESTED LOOPS- EXAMPLE
Write a program to toggle all the bits of P1 every 200
ms (using nested loops). Assume that the crystal
frequency is 11.0592 MHz
200ms = 200 x 1000 = 200,000 µ Sec