无法在嵌入式系统中递增寄存器
有问题的嵌入式系统是 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
好检查数据表:
因此,首先请确保 PORTC 上的所有外设功能均已关闭!
要查找哪个引脚被覆盖以输入,请使用 incurcuit 调试器!
Well check datasheet:
So first be sure that all peripheral functions on PORTC are switch off!
To find which pin is overridden to input use incurcuit debugger!
作为一个新手,我无法做到这一点,因此我放弃了 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.