访问手机版页面
你的位置:老古开发网 > Pic单片机 > PIC单片机C语言编程 > 正文  
PIC单片机实现延时x毫秒的功能设计
内容导读:

1、编写子程序DelayMS,实现延时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,实现1秒钟的精确延时。

list p=16f877A ; 标明所用的处理器类型

#include ; 调用头文件

;***** 变量声明*******************************************************

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 ; 程序结束

标签:PIC单片机,延时,
来源:工程师周亮 作者:lhl545545 时间:2019/6/12 15:22:00
相关阅读
推荐阅读
阅读排行
最近更新
商品推荐