; 1ms delay
; the crystal frequency is given as 12 MHz.
; Make a subroutine that will generate delay
; of exact 1 ms. Use this delay to
; generate square wave of 50 Hz on pin P2.0
ORG 0H
LOOP: SETB P2.0
MOV R6, #0AH
ACALL DELAY
CLR P2.0
MOV R6, #0AH
ACALL DELAY
SJMP LOOP
DELAY:
LP2: MOV R7, #0FAH
LP1: NOP ; 1 CYCLE
NOP ; 1+1=2 CYCLES
DJNZ R7, LP1 ; 1+1+2 = 4 CYCLES
DJNZ R6, LP2 ; 4×250 = 1000 CYCLES = 1000 µS = 1 MS
RET
END
Related topics:
8051 Program - find out of range data | 8051 Program - ones and twos complement | 8051 Program - check for NULL | 8051 Program - check nth bit of a byte | 8051 Program - 1sec delay timer | 8051 Program - memory subroutines | 8051 Program - math subroutines | 8051 Program - conversion subroutines
List of topics: 8051
No comments:
Post a Comment