PIC18F XC8 编译器 - 对象未初始化?

PIC18F XC8 compiler - objects not initialized?

我必须为一个新项目使用 Microchip PIC(需要在 5V 操作的 TQFP60 封装上使用高引脚数)。

我有一个大问题,我可能会错过一些东西(提前抱歉)。 IDE:MPLAB X 3.51 编译器:XC8 1.41

问题是,如果我将一个对象初始化为 0 以外的任何值,它将不会被初始化,并且在我到达 main() 时始终为零; 在模拟器中它可以工作,并且对象值是正确的。

简单示例:

#include <xc.h>
static int x= 0x78;
void main(void) {
   while(x){
     x++;
   }
   return;
}

在模拟器中,x 为 0x78,while(x) 为真。 但是当我使用 PICKIT3 将代码加载到 PIC18F67K40 时,x 为 0。

即使我执行一个简单的 sprintf 也会发生这种情况,并且它什么也不做,因为格式化文本字符串(字符数组)全是零。 sprintf(buf,"Number is %u",x")

我无法将任何对象初始化为零。 到底是怎么回事?任何帮助表示赞赏!

发现问题了,芯片有勘误问题,拿到了受影响的,奇怪,Farnell有卖的。更奇怪的是编译器一点准备都没有,连警告都没有说要小心!

勘误表:

Module: PIC18 Core

3.1 TBLRD requires NVMREG value to point to appropriate memory The affected silicon revisions of the PIC18FXXK40 devices improperly require the NVMREG<1:0> bits in the NVMCON register to be set for TBLRD access of the various memory regions. The issue is most apparent in compiled C programs when the user defines a const type and the compiler uses TBLRD instructions to retrieve the data from program Flash memory (PFM). The issue is also apparent when the user defines an array in RAM for which the complier creates start-up code, executed before main(), that uses TBLRD instructions to initialize RAM from PFM.