无法在嵌入式系统中递增寄存器

发布于 2025-01-02 21:55:44 字数 994 浏览 0 评论 0原文

有问题的嵌入式系统是 PIC 16F877,我试图用 incfsz 增加 PORTC 寄存器,但它仍然为 0。教程说这是可能的,但我无法让它工作。

list p=16f877
include "p16f877.inc"

__CONFIG    _CP_OFF & _CPD_OFF & _LVP_OFF & _WDT_OFF & _BODEN_OFF & _PWRTE_OFF & _XT_OSC


org 0x000           ; Start at the reset vector
nop                 ; Reserved for ICD in debu mode

Init
banksel PORTC
clrf    PORTC       ; Clear PORTC initially


; Set up the Timer0 control register

banksel OPTION_REG
movlw   B'10000111' ; Internal clock, prescaler assigned to Timer0
movwf   OPTION_REG  ; prescaler, 1:256

clrf    TRISC       ; PORTC all output  

banksel PORTC       ; Back to Bank 0

movlw   B'00000000'
Main

; Timer0 delay for acquisition


btfss   INTCON,T0IF ; Loop until T0IF = 1 (TMR0 rollover)
goto    Main
bcf     INTCON,T0IF
incfsz  PORTC , F  
goto Main


LoopWhilePushed         ; Loop if PORTB<0> = 0 (pressed)

btfss   PORTB,0
goto    LoopWhilePushed

goto    Main        ; Do it again

end

The embedded system in question is the PIC 16F877 and I'm trying to increment the PORTC register with incfsz but it remains at 0. The tutorial says this is possible but I can't get it to work.

list p=16f877
include "p16f877.inc"

__CONFIG    _CP_OFF & _CPD_OFF & _LVP_OFF & _WDT_OFF & _BODEN_OFF & _PWRTE_OFF & _XT_OSC


org 0x000           ; Start at the reset vector
nop                 ; Reserved for ICD in debu mode

Init
banksel PORTC
clrf    PORTC       ; Clear PORTC initially


; Set up the Timer0 control register

banksel OPTION_REG
movlw   B'10000111' ; Internal clock, prescaler assigned to Timer0
movwf   OPTION_REG  ; prescaler, 1:256

clrf    TRISC       ; PORTC all output  

banksel PORTC       ; Back to Bank 0

movlw   B'00000000'
Main

; Timer0 delay for acquisition


btfss   INTCON,T0IF ; Loop until T0IF = 1 (TMR0 rollover)
goto    Main
bcf     INTCON,T0IF
incfsz  PORTC , F  
goto Main


LoopWhilePushed         ; Loop if PORTB<0> = 0 (pressed)

btfss   PORTB,0
goto    LoopWhilePushed

goto    Main        ; Do it again

end

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

半衬遮猫 2025-01-09 21:55:44

好检查数据表:

启用外设功能时,应注意定义
每个 PORTC 引脚的 TRIS 位。某些外设会覆盖 TRIS 位
使引脚成为输出,而其他外设覆盖 TRIS 位
使引脚成为输入。

因此,首先请确保 PORTC 上的所有外设功能均已关闭!

要查找哪个引脚被覆盖以输入,请使用 incurcuit 调试器!

Well check datasheet:

When enabling peripheral functions, care should be taken in defining
TRIS bits for each PORTC pin. Some peripherals override the TRIS bit
to make a pin an output, while other peripherals override the TRIS bit
to make a pin an input.

So first be sure that all peripheral functions on PORTC are switch off!

To find which pin is overridden to input use incurcuit debugger!

烧了回忆取暖 2025-01-09 21:55:44

作为一个新手,我无法做到这一点,因此我放弃了 PORTC 并定义了一个常量,增加了该常量并将该 WORKING 寄存器移至 portc 中并得到了相同的结果。是的,我是一个放弃者。

更新:事实证明,这是一个微妙的硬件错误,它允许所有其他实验运行,但阻止这个实验运行。直到出于恶意重新布线后才发现这一点。

As a novice I cant do that, so I gave up on PORTC and defined a constant, incremented that and moved that WORKING regsiter into portc and got the same results. Yep Im a quitter.

UPDATE: As it turns out this it was subtle a hardware error that allowed all of the other experiments to function but prevent this one from working. It was not discovered until the circuit was rewired out of spite.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文