问题描述
我正在使用 PIC18 微处理器和汇编语言编程。我需要让我的 HPC 好奇心板上的 LED 以一定的顺序闪烁,并有一定的延迟。我的代码没有计时器和单步执行它可以工作,但我需要在每个 LED 之间添加延迟。当我添加计时器并运行程序时,我有大约 1 秒的延迟,但它只闪烁第一个 LED 序列,其余的不做。有人能告诉我为什么在延迟段之后代码返回到 GOTO Start
吗?
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Project 01,First Exercise,Operate the Curiosity HPC LEDs
;; Inputs: None
;; Outputs: LEDs are illuminated and extinguished
;; Side Effects: I/O Configured. Lights and extinguishes four LEDs.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; required header items
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
PROCESSOR 18F47Q10
#include <xc.inc>
#include "EE367_PIC18F47Q10_Setup01.inc"
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Constants
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
// none
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Allocate space for variables
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
// none
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Main program
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
PSECT Code,class=CODE,abs
Code:
ORG 0x000000
GOTO Start
ORG 0x000020
// Enter program body here
Start:
CLRF LATA,A // Clear Port A output bits,before activating Port A
CLRF TRISA,A // Make Port A an output port
Flash01:
SETF LATA,A // Turn on all bits on Port A
//delay
MOVLW BusyLoopDelay ;; Load up the input argument to BusyLoopTimer
CALL BusyLoopTimer ;; Call BusyLoopTimer
////////////////////
MOVLW 171
MOVWF LATA,A // Adds value of Wreg to LATA Turns on LED 1 3
//delay
MOVLW BusyLoopDelay ;; Load up the input argument to BusyLoopTimer
CALL BusyLoopTimer ;; Call BusyLoopTimer
//////////////////
movlw 342
movwf LATA,a// Adds value of Wreg to LATA LED 2 4
//delay
MOVLW BusyLoopDelay ;; Load up the input argument to BusyLoopTimer
CALL BusyLoopTimer ;; Call BusyLoopTimer
/////////////
CLRF LATA,A // Turn off all bits on Port A
//delay
MOVLW BusyLoopDelay ;; Load up the input argument to BusyLoopTimer
CALL BusyLoopTimer ;; Call BusyLoopTimer
nop
GOTO Flash01 // Repeat
Sleep // Halt
;; Material that goes into the constants section
BusyLoopDelay EQU 20 // Delay parameter,approx 4 mS per count.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Variables Section
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
GLOBAL BusyLoopDelayVar01
PSECT udata_acs
BusyLoopDelayVar01: DS 20 // Variable for counting out delay
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; BusyLoopTimer Routine to introduce delay.
;; The inner loop runs 256 iterations per count of the outer loop.
;; The inner loop (two instructions) uses four instruction cycles.
;; On Curiosity HPC,the outer loop runs about 4mS/count,;; indicating a 250KHz instruction clock (1 MHz Fast Clock).
;; (This is set by RSTOSC bits,in EE367_PIC18F47Q10_Setup01.inc)
;; Inputs: W Reg holds a delay count
;; Outputs: None
;; Side Effects: Uses and over writes variable BusyLoopDelayVar01
;; Modifies W and Status registers.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
BusyLoopTimer:
MOVWF BusyLoopDelayVar01,A // Store input to BusyLoopDelayVar01
CLRF WREG,A // Initialize WReg,first decrement gives 0xFF
BusyLoopTimer_Loop01: // Top of both inner and outer loops
DECFSZ WREG,F,A // [W]-1 -> [W],BRA BusyLoopTimer_Loop01 // BRA back to top until [W] == 0.
DECFSZ BusyLoopDelayVar01,A // [BLDVar01] - 1 -> [BLDVar01]
BRA BusyLoopTimer_Loop01 // BRA back to top until [BLDVar01]==0.
BusyLoopTimer_AllDone: // Many routines branch to finalizer and exit
Return
end Code
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)