PIC单片机实现延时x毫秒的功能设计

控制/MCU

1819人已加入

描述

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

打开APP阅读更多精彩内容
声明:本文内容及配图由入驻作者撰写或者入驻合作网站授权转载。文章观点仅代表作者本人,不代表电子发烧友网立场。文章及其配图仅供工程师学习之用,如有内容侵权或者其他违规问题,请联系本站处理。 举报投诉

全部0条评论

快来发表一下你的评论吧 !

×
20
完善资料,
赚取积分