我已经尝试了我的代码稍微削减版本,没有中断处理程序和中断所有禁用,但问题仍然发生。如果我从零开始,什么也不做,只有一个端口读取,那么它工作。但是在这种情况下(我从头开始),NCO被禁用了,但实际上我需要NCO在我的主代码中运行。我知道比特顺序颠倒。由于某种原因,我发现这是真的:PoBr= RB7 RB6 RB5 RB4 RB3 RB2 RB2 RB1 RB0在“MOVF PORTB,W”,然后“MOVWF DIPMEM”,我们得到这样的顺序:DIPMEM=RB0RB1 RB2 RB3 RB4 RB4 RB5 RB6 RB7为什么位颠倒超出我。有人知道吗?它不能是“罗摩腐败”,因为正如我所说的,只有一个PoBB读取导致问题,但是如果我从PoBB读取每一个比特,那么就没有问题,证明没有“RAM损坏”。我不使用调试器。我用P3编程PIC,然后把PDIP放进我的电路板,测试,然后删除,重新编程,再测试等等。……TREISB是B’11111111在复位,但我也手动写这个值到TISISB在我的init例程,毫无疑问地确保所有的Purb是S。每一个8个输入(包括引脚26)都有一个外部100K欧姆上拉到5V。此外,还有一个8开关DIP连接到8个输入中的每一个,当接通时会将个别输入接地。所以问题是,当我的DIP SW连接到Pi-26时。要在地上,PIC仍然认为Pi-26是关闭的/ 5V的,是的,我用DMM验证了,在我的DIP SW和电压电平上根本没有问题。ILVLB在复位时是B’11111111’,但我也用它手动测试到0,没有用。WPUB在复位时被设置为0,并且在R上也使用CLRF。我的代码中的EGISTER以确保内部的上拉电阻是不合格的。ODCONB在复位时设置为0,它不重要,因为它涉及到输出引脚上的电流或下沉电流——所有的端口引脚都被定义为输入。在任何情况下,我将该寄存器的默认值为0.SLRCONB设置为B’11111。在复位时,111′(“限制”)。我通常是这样的。但是根据您的请求,我在其init例程中使用了CLRF,但是问题仍然存在——改变转换速率没有正面影响。ANSELB在复位时是B’11111111’,但是在我的init例程中,我使用CLRF来确保所有引脚都是数字I/O。我不使用LATB,因为这与输出有关。以上都是与PORTB相关的寄存器,如表B 12-3所给出的修订B数据表的第196页:HTTP:/WW1.MICCHIP.COM/DeLoSs/En/DeVICEDC/OC0401826B.PDFand,虽然我确实有ISR,但它不做。调用任何写入RAM的例程(在0x077)。此外,当我写入RAM时,中断被禁用。
以上来自于百度翻译
以下为原文
I've tried a slightly cut-down version of my code, with no interrupt handler and interrupts all DISABLED, but the problem still occurs. If I start from scratch and do nothing but a PORTB read, then it works. But in that case (where I start from scratch), the NCO is disabled, but I actually need the NCO running in my main code.
I am aware about the bit order reversal. For some reason I have found this is true:
PORTB = RB7 RB6 RB5 RB4 RB3 RB2 RB1 RB0
After "movf PORTB, W" and then "movwf DIPmem" we get this order:
DIPmem = RB0 RB1 RB2 RB3 RB4 RB5 RB6 RB7
Why the bits are reversed is beyond me. Anyone know?
It cannot be "RAMa corruption" because like I said, only a PORTB read causes the problem, but if I read each and every bit from PORTB, then there is no problem, proving no "RAM corruption."
I am NOT using a debugger. I am programming the PIC with a PM3, then putting the PDIP into my breadboard, testing, then removing, reprogramming, retesting, etc.
More info for you...
TRISB is b'11111111' at Reset, but I also manually write that value into TRISB in my init routine, ensuring without a doubt that all of PORTB is set to INPUTS. Each of those 8 inputs (including pin 26) each have an external 100k-ohm pull-up to 5V. Furthermore, there is an 8-switch DIP connected to each of those 8 INPUTS that when switched ON will short the individual INPUTS to Ground. So the problem is that when I have my DIP SW tied to pin-26 to be ON/Ground, the PIC still thinks pin-26 is OFF/5V. And yes, I verified with a DMM that there are no problems at all with my DIP SW and voltage levels.
INLVLB is b'11111111' at Reset, but I also tested with it manually set to 0, to no avail.
WPUB is set to 0 at Reset, and I also use clrf on that register in my code to ensure internal pullups are Disabled.
ODCONB is set to 0 at Reset, and it shouldn't matter since it pertains to sourcing or sinking current on OUTPUT pins -- all my PORTB pins are defined as INPUTS. In any case, I leave that register at its default of 0.
SLRCONB is set to b'11111111' ("limited") at Reset. I normally leave it that way. But per your request, I used clrf on it in my init routine, but the problem remains -- changing slew rate has no positive impact.
ANSELB is b'11111111' at Reset, but I use clrf on it in my init routine to ensure all pins are DIGITAL I/O. I do NOT have any analog pins.
I don't use LATB because that pertains to Outputs.
The above are all the registers associated with PORTB, as per
TABLE 12-3 given on page 196 of the Revision B datasheet:
http://ww1.microchip.com/downloads/en/DeviceDoc/40001826B.pdf
And although I do have an ISR, it does not make calls to any routine that writes to my RAM (at 0x077). Furthermore, when I do write to that RAM, interrupts are disabled.