Professional Documents
Culture Documents
Module - 3 Notes Till Delay Subroutine
Module - 3 Notes Till Delay Subroutine
CPU executing an instruction takes a certain number of clock cycles. These are
referred as to as machine cycles.
The length of machine cycle depends on the frequency of the crystal oscillator
connected to 8051.
In original 8051, one machine cycle lasts 12 oscillator periods.
Find the period of the machine cycle for 11.0592 MHz crystal frequency.
Solution:
Machine cycle frequency = 11.0592 MHz / 12 = 921.6 kHz
Period of one machine cycle = 1/921.6 kHz = 1.085μs
Large Delay using nested loops: g
N
Write an ALP to generate delay of 1mS.
Solution:
One machine cycle =1.085 μS with crystal frequency of 11.0592MHz.
Total number of machine cycles required for generating 1mS delay = 1mS/1.085 μS =
= 921.6 nearly 922.
Initializing counter and RET instruction takes 3 machine cycles.
So remaining machine cycles are (922-3) = 919
Number of times the loop with 4 machine cycles should be repeated is = 919/4 =
229.75 nearly 230.
So initialize the R2 with 230 as a counter.
Instructions Machine
Cycles
DELAY:MOV R2, #230 1
HERE: NOP 1
NOP 1
DJNZ R2, HERE 2
RET 2
Instructions Machine
Cycles
DELAY: MOV R3, #04 1
L3 :MOV R2,#250 1
L2 : MOV R1,#230 1
L1 : NOP 1
NOP 1
DJNZ R1,L1 2
DJNZ R2,L2 2
DJNZ R3, L3 2
RET 2