完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
我想在程序内存中添加一些字符串(字符数组),最好是在某个位置,这样我可以识别一个已编程的设备并确定它的版本、程序日期等。程序存储器:我能够通过以下方法获得存储在ROM中的常数:最后我发现以下方法工作良好,至少对于XC8(C18使用#pragmas):我留下了注释行,这些注释行就是使用C18进行注释的方式。
以上来自于百度翻译 以下为原文 I wanted to add some strings (character arrays) to program memory, and ideally at a certain location, so that I can identify a programmed device and determine its version, program date, etc. The following should work, but the compiler optimization shows it to be not used, and it is not stored in the program memory: const char DATE[] = "07/09/2016"; I was able to get the constant stored in ROM by using the following: char temp; if(DATE[0] > 0) temp = DATE[0]; Finally I found the following, which works well, at least with XC8 (C18 uses #pragmas): //#pragma romdata IDstrings=0x100 __attribute__((address(0x100))) const char PROJECT[] = "SCRPCB1"; __attribute__((address(0x110))) const char VERSION[] = "1.10"; //#pragma code I left the commented lines, which are how this is done using C18. |
|
相关推荐
6个回答
|
|
试试这个:
以上来自于百度翻译 以下为原文 Try this: const char PROJECT[] @ 0x100 = "SCRPCB1"; const char VERSION[] @ 0x110 = "1.10"; |
|
|
|
您可能需要在程序中使用它来阻止编译器优化它。
以上来自于百度翻译 以下为原文 You may need to use it in the program to stop the compiler from optimizing it away. |
|
|
|
如果它被优化了,添加这个:或者使它们挥发。
以上来自于百度翻译 以下为原文 If it is being optimized away, add this: #asm global _PROJECT ; so it won't get optimized out for non-used global _VERSION #endasm or make them volatile. |
|
|
|
@addr结构似乎工作得很好,比_u._方法更简洁一些。我认为“volatile”只适用于RAM变量,而不适用于ROM常量。从给定位置开始,以下似乎是顺序分配几个常量的好方法:谢谢你的建议。
以上来自于百度翻译 以下为原文 The @addr construct seems to work well, and is a bit cleaner than the __attribute__ method. I think "volatile" applies only to RAM variables and not ROM constants. The following seems to be a good way to assign several constants sequentially, starting at a given location: __attribute__((address(0x110))) const char VERSION[] = "1.10", DATE[] = "07/09/2016"; Thanks for the ideas. |
|
|
|
const限定对象不是“常量”,而是“只读”。const volatile的示例用法来自http://publications.gbdir...onst_and_volatile.html。
以上来自于百度翻译 以下为原文 A const qualified object is not "constant" but is "read-only". An example usage of const volatile is from http://publications.gbdir...onst_and_volatile.html . Here's an article discussing Combining C's volatile and const Keywords. |
|
|
|
那些是很好的参考资料。它仍然有点混乱,但它是有道理的。一个问题是,Windows环境和PIC微控制器之间的硬件差别,在Windows环境中,一切都从磁盘存储转移到RAM,PIC微控制器具有独特的RAM、ROM和EEPROM内存空间以及SFR。似乎C18编译器(大约从2005年开始我几乎只使用它)和XC8有了一些重大的改变,我已经使用了几年。我之前的大多数项目,特别是那些没有使用PIC18处理器的项目,都是在组装中。这两个编译器之间的内存映射已经发生了很大的变化,而且我认为在每个编译器或汇编器中,还有很多用于变量和常量声明的可选方法,链接器。似乎在XC8中不再认可“ROM”或“ROMDATA”限定符。对于C18、PICC18、XC8和XC16等,也可能存在一些差异。以下是MPLABX帮助中的一些示例:示例:在Data MemoryPICC18#pragma psect oldbss=mybss int gi;C18#pragma udata mybss int gi;XC16 int_.(u.("mybss"))gi的用户部分中指定未初始化变量,其中oldbss是psect(.)的名称;示例:将变量Mabonga定位在地址0x100的Data MemoryPICC18 int Mabonga@0x100;C18#pragma idata myDataSection=0x100;int Mabonga=1;XC16 int_.((address(0x100))Mabonga=1;示例:指定要放置在程序Mem中的变量ORyPICC18constcharmy_const_const_my_const_const_char_my_const_const_.[10]={0,1,1,2,2,3,3,3,3,3,3,3,3,3,3,3,3,3,4,5,6,7,8,8,9};XC16常数或_u.u._my_const my_const my_const_((空间(auto_psv))char my_const my_const(空间)char my_const(空间(auto(auto_psv)))char my_const)char my_const_const_const_const(空间(空间(auto(auto(auto_psv)))char 5,6,7,8,9};示例:在Add处找到函数PrintString在程序MemoryPICC18 int PrintString(const char*s)@0x8000{...}C18#pragma代码myTextSection=0x8000;int PrintString(const char*s){...}XC16 int_.((address(0x8000))PrintString(const char s){...}示例编译器自动保存和恢复变量变量1和var2PICC18没有等价的C18#pragma中断isr0 save=var1,var2 void isr0(void){/*执行中断函数here*/}XC16 void_.(u inter._(u save_var1,var2))isr0(void){/*执行中断函数here*/}
以上来自于百度翻译 以下为原文 Those are some excellent references. It is still a bit confusing, but it makes sense. One issue is the difference in hardware between something like a Windows environment, where everything is transferred from disc storage to RAM, and a PIC microcontroller, which has distinct RAM, ROM, and EEPROM memory spaces, as well as SFRs. It also seems that there have been some major changes from the C18 compiler (which I had used almost exclusively since about 2005), and the XC8, which I have been using for a few years. Most of my earlier projects, particularly those not using the PIC18 processors, were in assembly. The memory mapping has changed considerably between the two compilers, and I think there are also quite a few alternate methods for variable and constant declarations within each compiler or assembler, and linker. It seems that the "rom" or "romdata" qualifiers are no longer recognized in XC8. There are also some differences for C18, PICC18, XC8, and XC16, among others, perhaps. Here are some examples from the MPLABX Help: Example: Specify an Uninitialized Variable in a User Section |
|
|
|
只有小组成员才能发言,加入小组>>
5129 浏览 9 评论
1984 浏览 8 评论
1914 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3149 浏览 3 评论
请问电源和晶体值之间有什么关系吗?PIC在正常条件下运行4MHz需要多少电压?
2212 浏览 5 评论
698浏览 1评论
586浏览 1评论
有偿咨询,关于MPLAB X IPE烧录PIC32MX所遇到的问题
467浏览 1评论
PIC Kit3出现目标设备ID(00000000)与预期的设备ID(02c20000)不匹配。是什么原因
603浏览 0评论
495浏览 0评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-3 06:50 , Processed in 1.179286 second(s), Total 89, Slave 72 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号