PIC单片机实现x ms/1s钟精确延时
;**************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 ;
;------------------------------------------------------------------------------list p=16f877A ; 标明所用的处理器类型#include <p16f877A.inc> ; 调用头文件 ;***** 变量声明*******************************************************
L1 EQU 0x70 ;延时函数循环变量
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 ;
;-----------------------------子函数-------------------------
;**************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 ; 程序结束
本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!
