我必须使用Microchip PIC进行一个新项目(需要使用5V工作的TQFP60封装的高引脚数)。
我有一个很大的问题,我可能会错过一些事情(提前抱歉)。 IDE:MPLAB X 3.51编译器:XC8 1.41
问题是,如果我初始化一个对象为0以外的任何东西,它将不会被初始化,并且当我到达main()时它总是0。 在模拟器中它可以工作,并且对象值是正确的。
简单的例子:
#include <xc.h> static int x= 0x78; void main(void) { while(x){ x++; } return; }在模拟器中,x是0x78,while(x)是true。 但是当我使用PICKIT3将代码加载到PIC18F67K40时,x为0。
即使我做了一个简单的sprintf,也会发生这种情况,并且它不会执行任何操作,因为格式化文本字符串(char数组)完全是零。 sprintf(buf,“Number is%u”,x“)
我无法将任何对象初始化为零。 到底是怎么回事? 任何帮助感谢!
I have to use a Microchip PIC for a new project (needed high pin count on a TQFP60 package with 5V operation).
I have a huge problem, I might miss something (sorry for that in advance). IDE: MPLAB X 3.51 Compiler: XC8 1.41
The issue is that if I initialize an object to anything other than 0, it will not be initialized, and always be zero when I reach the main(); In simulator it works, and the object value is the proper one.
Simple example:
#include <xc.h> static int x= 0x78; void main(void) { while(x){ x++; } return; }In simulator the x is 0x78 and the while(x) is true. BUT when I load the code to the PIC18F67K40 using PICKIT3, the x is 0.
This happening even if I do a simple sprintf, and it does nothing as the formatting text string (char array) is full of zeros. sprintf(buf,"Number is %u",x")
I can not initialize any object apart to be zero. What is going on? Any help appreciated!
最满意答案
发现问题,该芯片有一个勘误问题,我得到了一个有效的,奇怪的,Farnell销售它。 更奇怪的是,编译器没有为此做好准备,甚至没有给出警告说要小心!
勘误注释:
模块:PIC18内核
3.1 TBLRD要求NVMREG值指向适当的存储器PIC18FXXK40器件的受影响芯片版本不正确地要求将NVMCON寄存器中的NVMREG <1:0>位设置为各种存储器区域的TBLRD访问。 当用户定义一个const类型并且编译器使用TBLRD指令从程序闪存(PFM)中检索数据时,编译的C程序中最明显的问题是。 当用户在RAM中定义一个编译器创建启动代码并在main()之前执行的数组时,该问题也很明显,该代码使用TBLRD指令从PFM初始化RAM。
Found the problem, The chip has an errata issues, and I got the one which is effected, strange, Farnell sells it. More strange that the compiler is not prepared for that, does not even give a warning to say to be careful!
Errata note:
PIC18F XC8编译器 - 对象未初始化?(PIC18F XC8 compiler - objects not initialized?)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.
我必须使用Microchip PIC进行一个新项目(需要使用5V工作的TQFP60封装的高引脚数)。
我有一个很大的问题,我可能会错过一些事情(提前抱歉)。 IDE:MPLAB X 3.51编译器:XC8 1.41
问题是,如果我初始化一个对象为0以外的任何东西,它将不会被初始化,并且当我到达main()时它总是0。 在模拟器中它可以工作,并且对象值是正确的。
简单的例子:
#include <xc.h> static int x= 0x78; void main(void) { while(x){ x++; } return; }在模拟器中,x是0x78,while(x)是true。 但是当我使用PICKIT3将代码加载到PIC18F67K40时,x为0。
即使我做了一个简单的sprintf,也会发生这种情况,并且它不会执行任何操作,因为格式化文本字符串(char数组)完全是零。 sprintf(buf,“Number is%u”,x“)
我无法将任何对象初始化为零。 到底是怎么回事? 任何帮助感谢!
I have to use a Microchip PIC for a new project (needed high pin count on a TQFP60 package with 5V operation).
I have a huge problem, I might miss something (sorry for that in advance). IDE: MPLAB X 3.51 Compiler: XC8 1.41
The issue is that if I initialize an object to anything other than 0, it will not be initialized, and always be zero when I reach the main(); In simulator it works, and the object value is the proper one.
Simple example:
#include <xc.h> static int x= 0x78; void main(void) { while(x){ x++; } return; }In simulator the x is 0x78 and the while(x) is true. BUT when I load the code to the PIC18F67K40 using PICKIT3, the x is 0.
This happening even if I do a simple sprintf, and it does nothing as the formatting text string (char array) is full of zeros. sprintf(buf,"Number is %u",x")
I can not initialize any object apart to be zero. What is going on? Any help appreciated!
最满意答案
发现问题,该芯片有一个勘误问题,我得到了一个有效的,奇怪的,Farnell销售它。 更奇怪的是,编译器没有为此做好准备,甚至没有给出警告说要小心!
勘误注释:
模块:PIC18内核
3.1 TBLRD要求NVMREG值指向适当的存储器PIC18FXXK40器件的受影响芯片版本不正确地要求将NVMCON寄存器中的NVMREG <1:0>位设置为各种存储器区域的TBLRD访问。 当用户定义一个const类型并且编译器使用TBLRD指令从程序闪存(PFM)中检索数据时,编译的C程序中最明显的问题是。 当用户在RAM中定义一个编译器创建启动代码并在main()之前执行的数组时,该问题也很明显,该代码使用TBLRD指令从PFM初始化RAM。
Found the problem, The chip has an errata issues, and I got the one which is effected, strange, Farnell sells it. More strange that the compiler is not prepared for that, does not even give a warning to say to be careful!
Errata note:
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.
发布评论