完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
扫一扫,分享给好友
嗨,在实现压力传感器的头文件之后,我得到了“dist/default/.controller.X...obj:173:error:(1356)将引用psect nvBANK1(0xAC)的溢出修复为0x642/0x2->0x321(dist/default/.controller.X...obj 173/0x1C)的1字节”。我将问题缩小为“lps25hb.h”中的变量声明:无符号char PRESS_OUT[4]={0xA8,0x00,0x00,0x00};无符号char TEMP_OUT[4]={0xAB,0x00,0x00};无符号char FIFO_CTRL[2]={0x2E,0b00000000};如果我注释掉最后一行,错误就会消失。对于:unsigned char FIFO_CTRL[3]={0x2E,0b00000000}也是可以的;这对我来说似乎真的错了,但是我是新手,所以我可能错了。我试过不同的变量名,认为FIFO或CTRL可能受到限制,这没有帮助。直到这一行,LCD模块,温度为止一切都正常。NSOR,我没有任何警告。MCU是PIC16F946编译器是XC8 V1.38的任何想法是赞赏。非常感谢!
以上来自于百度翻译 以下为原文 Hi, I get a "dist/default/productioncontroller.X.production.obj:173: error: (1356) fixup overflow referencing psect nvBANK1 (0xAC) into 1 byte at 0x642/0x2 -> 0x321 (dist/default/productioncontroller.X.production.obj 173/0x1C)" after I implemented a header file for a pressure senor. I narrowed down the problem to a variable declaration in "lps25hb.h". unsigned char PRESS_OUT[4] = {0xA8, 0x00, 0x00, 0x00}; unsigned char TEMP_OUT[4] = {0xAB, 0x00, 0x00, 0x00}; unsigned char FIFO_CTRL[2] = {0x2E, 0b00000000}; If I comment out the last line, the error goes away. It is also ok with: unsigned char FIFO_CTRL[3] = {0x2E, 0b00000000}; This seems really wrong to me but I'm a newbie so I may be wrong. I tried different variable name thinking that FIFO or CTRL may be restricted, it doesn't help. Everything worked well until this line, the LCD module, a temperature sensor, I don't get any warning. MCU is PIC16F946 Compiler is XC8 V1.38 Any idea is appreciated. Thanks a lot! |
|
相关推荐
12个回答
|
|
这意味着什么?您不应该在函数标头中定义变量,除非您确信该报头只包含在项目中一次。即使如此,在一个C文件中,它是一个坏主意。在一个C文件中:未签名的CHAR PrimyOut[1]={0xa8,0x00,0x00,0x00 };未签名的char TimeExOUT(4)={0xAB,0x00,0x00,0x00 };未签名的chfFIFOO-CTRL(2)={0x2e,0b00兆};在头文件外无符号Car Press SuxOUT(4);ExtSub无符号Chan-TimeExOUT(4);Ar FIFOO-CTRL〔2〕;
以上来自于百度翻译 以下为原文 lps25hb.h Should that mean something? You should not have variables defined in a function header, unless you are sure the header is only included once in the project. Even then it is a bad idea. in one C file: unsigned char PRESS_OUT[4] = {0xA8, 0x00, 0x00, 0x00}; unsigned char TEMP_OUT[4] = {0xAB, 0x00, 0x00, 0x00}; unsigned char FIFO_CTRL[2] = {0x2E, 0b00000000}; in the header file extern unsigned char PRESS_OUT[4] ; extern unsigned char TEMP_OUT[4]; extern unsigned char FIFO_CTRL[2]; |
|
|
|
不要将初始值放入头文件中,这会将声明转换为定义。定义不应该在头文件中。参见:http://www. gMeDEV.NET/PA…文件C和C-R1798。
以上来自于百度翻译 以下为原文 Don't put initial values in header files. That converts your declarations into definitions. Definitions should NOT be in header files. See: http://www.gamedev.net/pa...files-in-c-and-c-r1798 |
|
|
|
谢谢,也许就是这样!报头包含在main.c中过一次,在lps25hc.c.BTW LPS25HB中只有一次是我需要配置/读取的压力传感器。
以上来自于百度翻译 以下为原文 Thanks, that may be it! The header is included once in the main.c and once in the lps25hc.c. BTW LPS25HB is the pressure sensor that I need to configure/read. Tomorrow I'll move the variables in the .c file and I'll report back. Cheers |
|
|
|
|
|
|
|
你能说得更具体些吗?什么神奇的数字?如果你在讨论数组,那就是寄存器地址和内容。
以上来自于百度翻译 以下为原文 Can you be more specific? What magic numbers? Those are register addresses and content if you're talking about the arrays. |
|
|
|
魔术数字是指在代码中使用的任何文字数字(十进制或其他)。什么是0x2e?你是如何决定FIFOXCCTL的第一个字节需要那个值的?它只是看起来…因此,公认的操作方式是_用一个有意义的名字_定义所有字面数字,并希望用注释解释它的来源。0和5月1日取决于它们使用的上下文,但LICT检查程序可能仍然会为您提供标记。这有助于确保当你从现在开始3年后打开这个项目,你仍然可以找出为什么你写的东西是一种特殊的方式。
以上来自于百度翻译 以下为原文 Magic numbers refer to any literal number (decimal or otherwise) that you use in your code. unsigned char FIFO_CTRL[2] = {0x2E, 0b00000000}; What is 0x2E? How did you decide the first byte of FIFO_CTRL needed to be that value? It just sort of appears... like magic. Thus, the accepted modus operandi is to #define all literal numbers with a meaningful name and hopefully with a comment explaining where it came from. 0 and 1 may be debatable depending on the context of their use, but lint checker programs may still flag you for it. This helps ensure when you open the project 3 years from now, you still can figure out why you wrote something a particular way. |
|
|
|
2E是压力传感器内的名为FIFO-CTRL的寄存器的地址。初始化设备时,我通过I2C发送一堆数据。I2C发送函数被初始化:char I2C_Send(char Address,char*Data,char Num)所以为了在压力传感器芯片内部配置FIFO控制,我做:I2C_Send(LPS25HB_Address,FIFO_CTRL,2)它将向LPS发送两个字节的数据。25HB_Address,第一个是寄存器地址以便指向那个寄存器,第二个是寄存器的数据内容。我不怀疑有更好的方法,我愿意学习一个有经验的程序员如何做到这一点。我真的很重视你所有的反馈和评论。干杯
以上来自于百度翻译 以下为原文 2E is the address of that register named FIFO_CTRL inside the pressure sensor. When I initialize the device I send a bunch of data over I2C. The I2C send function is initialized: char I2C_Send(char Address,char *Data,char Num) So to configure FIFO control inside the pressure sensor chip I do: I2C_Send(LPS25HB_Address, FIFO_CTRL, 2) That's going to send two bytes of data to the LPS25HB_Address, the first is the register address in order to point to that register, the next is the data content of that register. And yes, the chip address is defined #define LPS25HB_Address = 0xBA; I found this way a very easy way to do that. I don't doubt there are better ways and I'm willing to learn how would an experienced programmer do this. I really value all your feedback and comments. Cheers |
|
|
|
我相信你对魔术数字的评论有点过头了。我在代码中使用0x2e作为一个神奇数字的例子。摆脱这个特殊魔幻数字的简单方法如下:这样,您和所有未来的开发人员都知道数组中的特定字节是一个地址,这个地址的用途是什么,并提供了一个简单的地方来更改它。将这些#defines分组在一起(一般在头文件中)使得项目/模块非常容易配置和维护,而不是挖掘所有的初始化函数/变量定义以便稍后进行简单的更改。您可以根据需要将此应用于其他变量定义、数组大小等。这些只是好的编码实践。我坚持的另一个编码实践是永远不要使用编译器提供的基本变量类型。关键字可以在编译器之间改变,并且每个类型的大小也可以改变。“int”可以是16位或32位,这取决于您开发的是哪种芯片/计算机。您可以include
以上来自于百度翻译 以下为原文 I believe you're taking the magic numbers comment a little too far. I used 0x2E as an example of a magic number in your code. A simple way to get rid of that particular magic number would be as follows: #define FIFO_CTRL_ADDR (0x2E) // Address of FIFO_CTRL register in pressure sensor unsigned char FIFO_CTRL[2] = {FIFO_CTRL_ADDR, 0b00000000}; That way you and all future developers know that particular byte in the array is an address, what that address is for, and provides a simple place to change it. Grouping these #defines together (generally in header files) makes a project/module very easy to configure and maintain, rather than digging through all the initialization functions/variable definitions to make simple changes later. You can apply this to your other variable definitions, sizes of arrays, etc. as needed. These are just good coding practices. One more coding practice that I adhere to is never using the base variable types provided by the compiler. The keywords can change between compilers and the size of each type can change as well. "int" could be 16 bits or 32 bits depending on what chip/computer you're developing for. You can #include If your I2C routines and control logic are working correctly, wonderful! Simple is good. It doesn't look like you're doing anything strange on that front. |
|
|
|
你也可以去掉固定大小的数组,这样就不会因为打字错误而导致大小错误。
以上来自于百度翻译 以下为原文 Also you can get rid of the fixed size of the arrays. Instead of unsigned char PRESS_OUT[4] = {0xA8, 0x00, 0x00, 0x00}; unsigned char TEMP_OUT[4] = {0xAB, 0x00, 0x00, 0x00}; unsigned char FIFO_CTRL[2] = {0x2E, 0b00000000}; extern unsigned char PRESS_OUT[4] ; extern unsigned char TEMP_OUT[4]; extern unsigned char FIFO_CTRL[2]; you could do this unsigned char PRESS_OUT[ ] = {0xA8, 0x00, 0x00, 0x00}; unsigned char TEMP_OUT[ ] = {0xAB, 0x00, 0x00, 0x00}; unsigned char FIFO_CTRL[ ] = {0x2E, 0b00000000}; extern unsigned char PRESS_OUT[ ] ; extern unsigned char TEMP_OUT[ ]; extern unsigned char FIFO_CTRL[ ]; That way there is no danger of getting the size wrong because of a typo. |
|
|
|
谢谢大家!对于像我这样的新手来说,所有惊人的秘诀。我已经把它们全部实现了。
以上来自于百度翻译 以下为原文 Thanks guys! All amazing tips for a newbie like me . I've implemented them all. |
|
|
|
这解决了问题,但可以解决另一个问题。终端使用不知道数组大小对外部的影响很大吗?它可能在XC8,但不在上面。所以另一个选择是:
以上来自于百度翻译 以下为原文 That solves on problem but can case another. the end use does not know the Array size Does sizeof work on externs? It might in XC8 but not above that. so another option would be: code: unsigned char PRESS_OUT[PRESS_OUT_SIZE ] = {0xA8, 0x00, 0x00, 0x00}; unsigned char TEMP_OUT[ ] = {0xAB, 0x00, 0x00, 0x00}; unsigned char FIFO_CTRL[ ] = {0x2E, 0b00000000}; header: #define PRESS_OUT_SIZE 4 #define TEMP_OUTSIZE 4 #define FIFO_CTRL_SIZE 2 extern unsigned char PRESS_OUT[PRESS_OUT_SIZE ] ; extern unsigned char TEMP_OUT[TEMP_OUTSIZE ]; extern unsigned char FIFO_CTRL[ FIFO_CTRL_SIZE ]; |
|
|
|
注释变量并不意味着该变量会导致固定溢出。它会使编译器为其他变量使用不同的地址。你必须跟踪错误。在这个线程中,请参阅成员ASP的解释。http://www. McCux.com……1025127.ASPX?树=真
以上来自于百度翻译 以下为原文 Commenting out a variable does not mean that this variable causes the fixup overflow. It causes the compiler to use different addresses for other variables. You have to track down the error. See explanation by member asp in this thread. http://www.microchip.com/...1025127.aspx?tree=true |
|
|
|
只有小组成员才能发言,加入小组>>
5243 浏览 9 评论
2035 浏览 8 评论
1955 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3208 浏览 3 评论
请问电源和晶体值之间有什么关系吗?PIC在正常条件下运行4MHz需要多少电压?
2258 浏览 5 评论
779浏览 1评论
672浏览 1评论
有偿咨询,关于MPLAB X IPE烧录PIC32MX所遇到的问题
598浏览 1评论
PIC Kit3出现目标设备ID(00000000)与预期的设备ID(02c20000)不匹配。是什么原因
680浏览 0评论
578浏览 0评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-24 14:53 , Processed in 1.842289 second(s), Total 98, Slave 82 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号