如何解决我如何通过创建一个布尔变量而不是在分支中循环来处理这个程序?
我正在好奇 HPC 板上对 PIC1847q 处理器进行编程。我的任务是使用板上的 LED 设计一个太空堡垒卡拉狄加旋风遮阳板。我当前的代码确实创建和复制了 Cyclon,但我认为逻辑对于我“分配”这样做的方式是不正确的。我应该创建第二个变量,但我不确定如何执行此操作。我的问题是:如何使用带有布尔逻辑的布尔变量而不是我完成的方式获得相同的结果?我附上了任务的图片。 enter image description here
;; 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
// Configuration values for Timer 1 control registers
TMR1_CS_Bits EQU 00000001B // Set to TMR1CLK to FOSC/4 (Instruction Clock)
TMR1_Con_Bits EQU 00110011B // Set to ON,RD16,SYNC-bar,8x prescaler
TMR1_GCon_Bits EQU 00000000B // GE = 0,Gating is disabled
TMR1IF_Mask EQU 00000001B // TMR1IF bit is b0 or PIR4
TMR1IF_POSN EQU 0 // Ditto
InitialTMR1H EQU 0xe4 // Initial value for Two-byte TMR counter register
InitialTMR1L EQU 0x00 // 0xC000 gives about 1/2 second delay
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
// none
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Allocate space for variables
Global TMR1_Initializer
PSECT udata_acs
TMR1_Initializer: DS 2 // Value used to initialize TMR 1,each cycle
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
// none
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; InitializeTimerOne: Setup configuration for TMR1 to count up
;; Inputs: none
;; Outputs: none
;; Side Effects: Reinitializes the TMR1 counter register,;; and clears TMR1 IF flag bit
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Main program
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
PSECT Code,class=CODE,abs
Code:
ORG 0x000000
GOTO Start
ORG 0x000020
// Enter program body here
Start:
Call InitializeIO_Ports
Flash01:
//initial state
movlw 16
movwf LATA,a// Adds value of Wreg to LATA LED 2 4
BRA LeftRotate
RightRotate:
CALL InitializeTimerOne // Comment required
CALL DelayTMR1 ;; Call DelayTMR1
RRNCF LATA,a
CALL InitializeTimerOne // Comment required
CALL DelayTMR1 ;; Call DelayTMR1
RRNCF LATA,a
CALL InitializeTimerOne // Comment required
CALL DelayTMR1 ;; Call DelayTMR1
RRNCF LATA,a
CALL InitializeTimerOne // Comment required
CALL DelayTMR1 ;; Call DelayTMR1
BNZ LeftRotate
LeftRotate:
RLNCF LATA,a
CALL InitializeTimerOne // Comment required
CALL DelayTMR1 ;; Call DelayTMR1
RLNCF LATA,a
BNZ RightRotate
Sleep // Halt
InitializeTimerOne:
MOVLW TMR1_GCon_Bits ;; 8 bits for the TMR1 Gating Cntl Reg
MOVWF T1GCON,A
MOVLW TMR1_CS_Bits ;; 8 bits for the TMR1 clock signal Cntl Reg
MOVWF T1CLK,A
MOVLW TMR1_Con_Bits ;; 8 bits for the TMR1 Main Cntl Reg
MOVWF T1CON,A ;; Note: this instruction starts the timer
MOVLW InitialTMR1L ;; Set an initial value into var TMR1_Initializer
MOVWF TMR1_Initializer,A ;; which is a variable used to initialize
MOVLW InitialTMR1H ;; the TMR1 counter on each pass.
MOVWF TMR1_Initializer,A
RETURN
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; DelayTMR1: Busy wait until timer one times out.
;; Will initialize TIMR1 counter register and return immediately,;; if timer 1 is already expired.
;; Inputs: none
;; Outputs: none
;; Side Effects: Reinitializes the TMR1 counter reg and clears TMR1 IF flag bit
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
DelayTMR1:
BANKSEL PIR4 ;; The flag bit is in SFR PIR4,Banked Mode required
DelayTMR1_Repeat01:
MOVF PIR4,W,B ;; These two steps use AND masking to detect
ANDLW TMR1IF_Mask ;; the TMR1 IF flag bit.
BZ DelayTMR1_Repeat01 ;; Go into busy wait until TIMR1IF is set.
MOVFF TMR1_Initializer,TMR1H ;; Reinitialize the 16-bit TMR1 counter
MOVFF TMR1_Initializer,TMR1L ;;
BCF PIR4,TMR1IF_POSN,B ;; Clear the flag,ready for the next cycle
RETURN
InitializeIO_Ports:
CLRF LATA,A // Clear Port A output bits,before activating Port A
CLRF TRISA,A // Make Port A an output port
return
end Code
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。