×
单片机 > 单片机程序设计 > 详情

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

发布时间:2021-01-21 发布时间:
|

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单片机  延时  x毫秒  寄存器

『本文转载自网络,版权归原作者所有,如有侵权请联系删除』

热门文章 更多
ARM 汇编的必知必会