1、編寫子程序DelayMS,實現(xiàn)延時x毫秒的功能,x由w寄存器中的值設定。
;**************DelayMS**************
DelayMS ; 延時x毫秒,x由變量w寄存器設定
movwf L1 ;
Loop1
movlw .39 ;
movwf L2 ;
Loop2
movlw .31 ;
movwf L3 ;
Loop3
nop ;
decfsz L3, f ;
goto Loop3 ;
decfsz L2, f ;
goto Loop2 ;
decfsz L1, f ;
goto Loop1 ;
return ;
;------------------------------------------------------------------------------
2、編寫子程序Delay1S,實現(xiàn)1秒鐘的精確延時。
list p=16f877A ; 標明所用的處理器類型
#include
;***** 變量聲明*******************************************************
L1 EQU 0x70 ;延時函數(shù)循環(huán)變量
L2 EQU 0x71
L3 EQU 0x72
;**********************************************************************
org 0x0000 ; 復位入口地址
;--------------------------------Main的代碼-------------------------------------
main
banksel TRISB;
bcf TRISB, RB0;
banksel PORTB;
Loop
bsf PORTB, RB0;
movlw .100;
call Delay1S;
bcf PORTB, RB0;
movlw .100;
call Delay1S;
goto Loop ;
;-----------------------------子函數(shù)-------------------------
;**************Delay1S**************
Delay1S ; 延時x毫秒,x由變量w寄存器設定
movwf L1 ;
Loop1
movlw .200 ;
movwf L2 ;
Loop2
movlw .62 ;
movwf L3 ;
Loop3
nop ;
decfsz L3, f ;
goto Loop3 ;
decfsz L2, f ;
goto Loop2 ;
decfsz L1, f ;
goto Loop1 ;
return ;
;----------------------------------------------------------------------
END ; 程序結(jié)束