各種匯編延時(shí)程序大集合
精確延時(shí)計(jì)算公式:
延時(shí)時(shí)間=[(2*第一層循環(huán)+3)*第二層循環(huán)+3]*第三層循環(huán)+5
;延時(shí)5秒左右
DELAY5S:PUSH
DELAY5S_0:MOV
DELAY5S_1:MOV
;513微秒延時(shí)程序
DELAY:
DELAY1: DJNZ
;10毫秒延時(shí)程序
DL10MS: MOV
DL10MS1:LCALL
;0.1s延時(shí)程序12mhz
DELAY: MOV R6,#250
DL1: MOV R7,#200
DL2: DJNZ R6,DL2
;延時(shí)1046549微秒(12mhz)
;具體的計(jì)算公式是:
;((((r7*2+1)+2)*r6+1)+2)*r5+1+4 = ((r7*2+3)*r6+3)
*r5+5
DEL : MOV
DEL1: MOV
DEL2: MOV
;1秒延時(shí)子程序是以12MHz晶振
Delay1S:mov
del0:
del1:
;1秒延時(shí)子程序是以12MHz晶振為例算指令周期耗時(shí)
KK: MOV
K1: MOV
K2: MOV
K3: NOP
128*256*10=327680
2*128*256*10=655360
2*256*10=5120
;2指令周期21+10+2560+327680+655360+5120+20+2=990753
;約等于1秒1秒=1000000微秒
;這個(gè)算下來也只有0.998抄
T_0:
D1:
D2:
;這樣算下來應(yīng)該是1.000011秒
T_0:
D1:
D2:
DELAY_2S:
DELAY_100MS:
DELAY_10MS:
DELAY10MS:
(11.0592mhz)
DELAY10MSA:
DELAY_500MS:
DELAY_175MS:
delaY_120MS:
delay_60ms:
delay_30ms:
DELAY_5MS:
;===================================
DELAY_MS:
RET
;===================================
DELAY2400:
/1.024=2390
DELAY24001:
DELAY: ;延時(shí)子程序(1秒)
MOV R0,#0AH
DELAY1: MOV R1,#00H
DELAY2: MOV R2,#0B2H
DJNZ R2,$
DJNZ R1,DELAY2
DJNZ R0,DELAY1
RET
MOV R2,#10 ;延時(shí)1秒
LCALL DELAY
MOV R2,#50 ;延時(shí)5秒
LCALL DELAY
DELAY: ;延時(shí)子程序
PUSH R2
PUSH R1
PUSH R0
DELAY1: MOV R1,#00H
DELAY2: MOV R0,#0B2H
DJNZ R0,$
DJNZ R1,DELAY2 ;延時(shí) 100 mS
DJNZ R2,DELAY1
POP R0
POP R1
POP R2
RET
是50.001ms 算法是:
0.001ms+200*0.001ms+200*0.001ms+200*123*0.002ms+200*0.002ms
;(123*2+4)*200+1
2: DEL: MOV R7, #200
RET
D500MS:
PUSH PSW
SETB RS0
MOV R7,#200
D51: MOV R6,#250
D52: NOP
NOP
NOP
NOP
DJNZ R6,D52
DJNZ R7,D51
POP PSW
RET
DELAY: ;延時(shí)1毫秒
PUSH PSW
SETB RS0
MOV R7,#50
D1: MOV R6,#10
D2: DJNZ R6,$
DJNZ R7,D1
POP PSW
RET
評論