为什么此 PIC 汇编代码中的位没有移动?

Why isn't the bits shifting in this PIC assembler code?

我刚刚开始熟悉 PIC 汇编程序并尝试相应地移位和点亮 LED。

我正在使用带有 MPLAB X 的 Xpress DM164140 开发板 IDE。

我在 RA0-RA3 上有 4 个 LED。 我想通过移动 R5 "user" 寄存器的值并将其分配给 PORTA 寄存器来一个接一个地点亮它们。

这是我正在使用的汇编代码。如果不使用 DELAY 子程序,所有 4 个 LED 都会亮起,但是当我使用 DELAY 子程序时,RA3 不会亮起。转变一直持续到 RA3。

所以问题一定出在延迟子程序中。想不通。 我还尝试了 lslf 和 addwf 指令来尝试实现所需的行为,但到目前为止没有成功。

有人知道为什么会这样吗?

提前致谢!

    ; Assembly source line config statements

#include "p16f18855.inc"

; CONFIG1
; __config 0x3FEC
 __CONFIG _CONFIG1, _FEXTOSC_OFF & _RSTOSC_HFINT1 & _CLKOUTEN_OFF & _CSWEN_ON & _FCMEN_ON
; CONFIG2
; __config 0x3FFF
 __CONFIG _CONFIG2, _MCLRE_ON & _PWRTE_OFF & _LPBOREN_OFF & _BOREN_ON & _BORV_LO & _ZCD_OFF & _PPS1WAY_ON & _STVREN_ON
; CONFIG3
; __config 0x3FFF
 __CONFIG _CONFIG3, _WDTCPS_WDTCPS_31 & _WDTE_ON & _WDTCWS_WDTCWS_7 & _WDTCCS_SC
; CONFIG4
; __config 0x3FFF
 __CONFIG _CONFIG4, _WRT_OFF & _SCANE_available & _LVP_ON
; CONFIG5
; __config 0x3FFF
 __CONFIG _CONFIG5, _CP_OFF & _CPD_OFF

 ;user define registers @ bank0   
R1 equ 0x20
R2 equ 0x21
R3 equ 0x22
R4 equ 0x23
R5 equ 0x24
R6 equ 0x25

RES_VECT  CODE    0x0000            ; processor reset vector
    GOTO    START                   ; go to beginning of program

; TODO ADD INTERRUPTS HERE IF USED

MAIN_PROG CODE                      ; let linker place main program

START
    CLRW
    MOVLB 0x11 ;select bank17 to change clock freq of HFINT1
    ;(high frequency internal oscillator)
    MOVLW 0x06
    MOVWF OSCFRQ    ;clock divider of 32 = 1MHz frequency

    MOVLB 0x00  ;move 0x00 to BSR aka select bank0, where TRISA reg is located     
    MOVLW 0xF0  
    MOVWF TRISA ;RA0-3 to output and RA4-RA7 to input
    MOVLW 0x01 ;00000001
    MOVWF R5
    MOVWF PORTA


MAIN
    CALL DELAY  ;delay to see the blinking
    bcf STATUS,C    ;clear carry bit
    rlf R5,1    ;shift contents of R5 by 1 to the left and save it to R5
    MOVF R5,0   ;move shifted R5 to W
    movwf PORTA ;move W to PORTA

    GOTO MAIN


;1 instruction cycles takes 4 clock cycles
;count to 250000@1MHz clock to get 1s delay
DELAY
    MOVLW 0x08  ;8
    MOVWF R1
DELAY_1
    MOVLW 0xFA  ;250
    MOVWF R2
DELAY_2
    MOVLW 0xFA  ;250
    MOVWF R3    
DELAY_3
    DECFSZ R3   ;decrease R2
    GOTO DELAY_3    
    DECFSZ R2   ;decrease R1
    GOTO DELAY_2
    DECFSZ R1   ;decrease R1
    GOTO DELAY_1
    RETURN

    END

据我所知,您已启用 看门狗定时器。可能 看门狗定时器 在第 4 个 LED 亮起之前重置了微控制器。

所以你必须在主循环的某处清除看门狗定时器

输入指令...

CLRWDT

标签后 MAIN.

可能为时已晚,但无论如何。 对于输出,您必须使用 LATx 命令。所以将两个字符串替换为 PORTA 到 LATA。