在汇编代码中实现延迟功能

时间:2014-03-16 16:52:20

标签: assembly delay pic mplab

我一直在尝试让K_100MS子程序用于PIC16F84微控制器的简单LED点亮程序。以下代码构建正常,但在Proteus ISIS中模拟它时延迟没有实现。有人能告诉我我做错了吗?

list      p=16f84         ; list directive to define processor
#include <p16F84.inc>        ; processor specific variable definitions
errorlevel  -302 , -207             ; suppress message 302 from list file

__config _XT_OSC & _CP_OFF & _PWRTE_OFF & _WDT_OFF


ORG     0x00            ; processor reset vector
goto    start              ; go to beginning of program


COUNT_H equ 30h ; 2-byte counter
COUNT_L equ 31h ; at File 20:1h
K equ 32h ; Temporary storage for K
N equ d'130'  
DELAY_K100MS
movwf K ; Put K away in a register file
; Task 1: DO 100ms delay
movlw N ; Set up high count to 130
movwf COUNT_H
clrf COUNT_L ; and low count to 256
DK_LOOP
decfsz COUNT_L,f ; Decrement LS count to zero
goto DK_LOOP ; taking in all H*[(256*3)-1]˜
decfsz COUNT_H,f ; Repeat for the MS byte
goto DK_LOOP ; taking in all (H*3)-1˜
; Task 2: Decrement K
decfsz K,f
; Task 3: WHILE K > 0
goto DK_LOOP ; REPEAT WHILE K > 0
FINI return




PORTB                        EQU     H'0006'
TRISB                        EQU     H'0086'
STATUS                       EQU     H'0003'
RP0                          EQU     H'0005'


start:
bsf STATUS, RP0
clrf TRISB
bcf STATUS, RP0
movlw   b'01111110'
movwf PORTB
movlw d'10' ; 10 x 0.1s gives one second
call DELAY_K100MS 
clrf PORTB
end

0 个答案:

没有答案