Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
6 views3 pages

Module4 2

The document discusses assembly language programming for time delays in 8051 microcontrollers, detailing how machine cycles are calculated based on crystal oscillator frequencies. It provides examples of calculating execution times for various instructions and programs, highlighting the impact of crystal frequency and 8051 design on delay accuracy. Additionally, it includes assembly language programs for outputting binary and BCD counting sequences on port 1.

Uploaded by

gaxobi4935
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views3 pages

Module4 2

The document discusses assembly language programming for time delays in 8051 microcontrollers, detailing how machine cycles are calculated based on crystal oscillator frequencies. It provides examples of calculating execution times for various instructions and programs, highlighting the impact of crystal frequency and 8051 design on delay accuracy. Additionally, it includes assembly language programs for outputting binary and BCD counting sequences on port 1.

Uploaded by

gaxobi4935
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Module-4 Assembly Language Program Time Delay

Atria Institute of Technology


 CPU executing an instruction takes a certain number of clock cycles
Bengaluru-560024
 These are referred as to as Machine cycles
Department of Electronics and Communication Engineering
 The length of machine cycle depends on the frequency of the crystal oscillator
connected to 8051
 Frequency of Crystal Oscillator in 8051  4MHz to 30MHz
 11.0592 MHz is compatible with Serial port of IBM PC
 In 8051, one machine cycle lasts 12 oscillator periods

8051 Stack, I/O Port Interfacing and Programming


By,
Module-4 NATARAJA N
Asst. Prof, Dept. of ECE,
Atria IT-Bangalore.

Atria Institute of Technology NATARAJA N, Dept. of ECE, AIT

Module-4 Assembly Language Program Time Delay Module-4 Assembly Language Program Time Delay

Find the period of the machine cycle for 11.0592 MHz crystal frequency
For 8051 system of 11.0592 MHz, find how long it takes to
Solution: execute each instruction.
11.0592 MHz/12 = 921.6 kHz; (a) MOV R3,#55 (b) DEC R3 (c) DJNZ R2,target
machine cycle is 1/921.6 kHz = 1.085μs (d) LJMP (e) SJMP (f) NOP (g) MUL AB

Solution:
Machine cycles Time to execute
(a) 1 1x1.085μs = 1.085μs
Find the period of the machine cycle for 20 MHz crystal frequency (b) 1 1x1.085μs = 1.085μs
(c) 2 2x1.085μs = 2.17μs
Solution: (d) 2 2x1.085μs = 2.17μs
20 MHz/12 = 1.66 MHz; (e) 2 2x1.085μs = 2.17μs
machine cycle is 1/1.66 MHz = 0.60μs (f) 1 1x1.085μs = 1.085μs
(g) 4 4x1.085μs = 4.34μs

Atria Institute of Technology NATARAJA N, Dept. of ECE, AIT Atria Institute of Technology NATARAJA N, Dept. of ECE, AIT
Module-4 Assembly Language Program Time Delay Module-4 Assembly Language Program Time Delay

Find the size of the delay in following program, if the crystal Find the size of the delay in following program, if the
frequency is 11.0592MHz. crystal frequency is 11.0592MHz.

MOV A,#55H Machine Cycle


AGAIN: MOV P1,A DELAY: MOV R3,#250 1
ACALL DELAY HERE: NOP 1
CPL A NOP 1
SJMP AGAIN NOP 1
;---time delay------- NOP 1
DELAY: MOV R3,#200 DJNZ R3,HERE 2
HERE: DJNZ R3,HERE RET 2
RET
Solution:
Solution: The time delay inside HERE loop is
Machine cycle [250(1+1+1+1+2)]x1.085μs = 1627.5μs.
DELAY: MOV R3,#200 1 • Largest Value of R3 is 255. { [ 250*(1+1+1+1+2)]+1+2}*1.085 μs
Adding the two instructions outside loop we =1630.755 μs
HERE: DJNZ R3,HERE 2 • To increase the Delay we can go for NOP
RET 2 have 1627.5μs + 3 x 1.085μs = 1630.755μs
Therefore, [(200x2)+1+2]x1.085μs = 436.255μs.

Atria Institute of Technology NATARAJA N, Dept. of ECE, AIT Atria Institute of Technology NATARAJA N, Dept. of ECE, AIT

Module-4 Assembly Language Program Time Delay Module-4 Assembly Language Program Time Delay

Find the size of the delay in following program, if the crystal Notice in nested loop, as in all other time delay  Two factors can affect the accuracy of the delay
frequency is 11.0592MHz. loops, the time is approximate since we have
 Crystal frequency
ignored the first and last instructions in the
Machine Cycle subroutine.  The duration of the clock period of the machine cycle is a function of this crystal frequency
DELAY: MOV R2,#200 1  8051 design
AGAIN: MOV R3,#250 1  The original machine cycle duration was set at 12 clocks
( { [ 250*(1+1+2)]+1+2}* 200)*1.085 μs
HERE: NOP 1  Advances in both IC technology and CPU design in recent years have made the 1-clock machine cycle
=217651 μs
NOP 1 a common feature
DJNZ R3,HERE 2
DJNZ R2,AGAIN 2
RET 2
Clocks per machine cycle for various 8051 versions:
Solution:
For HERE loop, we have (4x250)x1.085μs=1085μs. Chip/Maker Clocks per Machine Cycle
For AGAIN loop repeats HERE loop 200 times, so {( { [ 250*(1+1+2)]+1+2}* 200) +1+2 }*1.085 μs AT89C51 Atmel 12
we have 200x1085μs=217000μs. But “MOV =218522 . 255 μs
P89C54X2 Philips 6
R3,#250” and “DJNZ R2,AGAIN” at the start and
end of the AGAIN loop add (3x200x1.805)=651μs. DS5000 Dallas Semi 4
As a result we have 217000+651=217651μs. DS89C420/30/40/50 Dallas Semi 1

Atria Institute of Technology NATARAJA N, Dept. of ECE, AIT Atria Institute of Technology NATARAJA N, Dept. of ECE, AIT
Module-4 Assembly Language Program Time Delay Module-4 Assembly Language Program Time Delay

ALP to output the binary up counting(00h to 0ffh) sequence


on port1 and observe O/P on logic analyzer window.

Find the period of the machine cycle (MC) for various versions of ORG 0000H
8051, if XTAL=11.0592 MHz. SJMP 30H
ORG 30H
(a) AT89C51 (b) P89C54X2 (c) DS5000 (d) DS89C4x0
MOV P1,#00H ;Configure P1 As O/P Port
Solution: MOV A,#00H
(a) 11.0592MHz/12 = 921.6kHz; BACK: MOV P1,A ;LOAD P1 WITH INITIAL COUNT
MC is 1/921.6kHz = 1.085μs = 1085ns ACALL DELAY ;Give Delay Between Count
INC A ;ADD 01 To Increment The Count
(b) 11.0592MHz/6 = 1.8432MHz;
MC is 1/1.8432MHz = 0.5425μs = 542ns SJMP BACK
(c) 11.0592MHz/4 = 2.7648MHz ;
MC is 1/2.7648MHz = 0.36μs = 360ns
(d) 11.0592MHz/1 = 11.0592MHz; DELAY: MOV R4,#0FFH ;Delay Between Counts
LOOP3: MOV R5,#0FFH
MC is 1/11.0592MHz = 0.0904μs = 90ns
LOOP2: MOV R6,#04H
LOOP1: NOP
DJNZ R6, LOOP1
DJNZ R5, LOOP2
DJNZ R4, LOOP3
RET Note:
END For Down Counter use DEC A

Atria Institute of Technology NATARAJA N, Dept. of ECE, AIT Atria Institute of Technology NATARAJA N, Dept. of ECE, AIT

Module-4 Assembly Language Program Time Delay Atria Institute of Technology


Bengaluru-560024
ALP to output the BCD up counting(00 to 99) sequence on port1 and
observe o/p on logic analyzer window. Department of Electronics and Communication Engineering
ORG 0000H
SJMP 30H
ORG 30H
MOV P1,#00H ;Configure P1 As O/P Port
MOV A,#00H
BACK: MOV P1,A ;Load P1 With Initial Count
ACALL DELAY ;Delay
ADD A,#01 ;Add 01 To Increment The Count
DA A
SJMP BACK

DELAY:
L3:
MOV R4,#0FFH
MOV R5,#0FFH
;Delay Between Counts
Thanks for watching…..
L2: MOV R6,#04H
L1: NOP
DJNZ R6,L1 By,
DJNZ R5,L2 NATARAJA N
DJNZ R4,L3 Note: For Down Counter Asst. Prof, Dept. of ECE,
RET Atria IT-Bangalore
Start with MOV A, #99H
END
& than use ADD A,#99H
Atria Institute of Technology NATARAJA N, Dept. of ECE, AIT

You might also like