完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
大家好,我想把指针指向xC8中的char变量的值。字符的值没有改变,它仍然是0。这里是代码:空函数(unChar char * DATAS,未签名int Ni){un签署char timeIn;未签名int TuncCl= 0;未签名int TimeLINE=0;(i=0;i & lt;num;i++){TimigiNe= *(DATAS+TEMPPLINE);TEMPLINE+++;}非常感谢。埃加德,
以上来自于百度翻译 以下为原文 Hi everybody, I'm trying to assign the value of a pointer to a char variable in XC8. The char's value didn't change, it is still 0. Here is the code: void function(unsigned char * datas,unsigned int num) { unsigned int i; unsigned char tempOriginal; unsigned int tempcol=0; unsigned int templine=0; for(i=0;i tempOriginal=*(datas+templine); templine++; } Thanks a lot. Best regards, |
|
相关推荐
18个回答
|
|
你是如何测试这个的?这个bug很可能在你没有显示的代码中。
以上来自于百度翻译 以下为原文 How did you test this? The bug is most probably in the code you didn't show. |
|
|
|
最可能的时间被编译器消除了,因为它不在任何地方使用。
以上来自于百度翻译 以下为原文 Most likely tempOriginal has been eliminated by the compiler because it is not used anywhere. |
|
|
|
大家好,我用一个断点测试这个,写的是“模板+ +”。我没有显示的代码只由SPI发送的变量Timigial.非常感谢,最好的问候,
以上来自于百度翻译 以下为原文 Hi everybody, I test this with a breakpoint in the line which is written "templine++". The code I didn't show only send by SPI the variable tempOriginal. Thanks a lot. Best regards, |
|
|
|
正如NorthGuy所说,你所发布的代码从来没有使用TimigIn,所以如果它没有被标记为“易失性”,那么编译器就足够聪明了,可以丢弃任何代码写入它,因为它从来没有被使用过。这意味着你认为“无关紧要”的代码,真的“很重要”。如果一些奇怪的事情发生了,发布你的真实代码,而不是你认为你的代码正在做的总结。
以上来自于百度翻译 以下为原文 As NorthGuy said, the code you posted never uses tempOriginal, so if it is not marked as "volatile", then the compiler is smart enough to throw away any code writing to it, because it is never used. That means code you think "does not matter", really "does matter" ! If something odd is happening, post your REAL code, not a summary of what you think your code is doing. |
|
|
|
简而言之,代码看起来不错。这也意味着:问题还是在哪里。或者您的测试代码正在挖掘优化器。或者还有其他问题。你使用的是什么版本的MPLABX和编译器?
以上来自于百度翻译 以下为原文 In short the code appears to be ok. This means either: The issue is else where. Or you test code is digging the optimizer. Or there could be other issues. What version of MPLabX and compiler are you using? |
|
|
|
嗨,谢谢你的回复。这里是完整的代码:空函数(unChar char * DATAS,未签名int Ni){无符号char TimeIn;未签名int TimeLINE=0;(i=0;i & lt;num;i++){TimigiNe= *(DATAS+TEMPPLINE);TEMPLINE+++;} sEndoSPi(TimigialIn);}我使用的编译器是XC8,MPLAB版本是3.61.很多!最好的问候,
以上来自于百度翻译 以下为原文 Hi, thanks for the replies. Here is the complete code: void function(unsigned char * datas,unsigned int num) { unsigned int i; unsigned char tempOriginal; unsigned int templine=0; for(i=0;i tempOriginal=*(datas+templine); templine++; } SendSPI(tempOriginal); } The compiler I use is XC8 and the the MPLAB version is 3.61. Thanks a lot! Best regards, |
|
|
|
sEndoScript()调用应该在循环中吗?该代码可以简化为
以上来自于百度翻译 以下为原文 Is the SendSPI() call supposed to be inside the loop? That code can be reduced to void function(unsigned char *datas, unsigned int num) { SendSPI(datas[num-1]); } |
|
|
|
你怎么知道它没有改变?你如何测试?如果您的数据源包含0个或指针运算不同于您认为它应该做的,那么所显示的代码可能不包含任何问题。将时间初始化为0x42并查看发生了什么。这也取决于你的期望。如果您发布更多代码,请使用代码标记。
以上来自于百度翻译 以下为原文 How do you know it did not change ? How do you test ? If your data source contains 0's or the pointer arithmetic works different from what you think it should do, then the shown code might not contain any problem. Initialize tempOriginal to 0x42 and see what happens. Your code shown still is not "complete" in the sense that we could see the problem. This also depends on your expectations. If you post more code, please use code tags. |
|
|
|
我测试,调试代码,当我初始化Timigito到0x42,它工作。
以上来自于百度翻译 以下为原文 I tested, debugging the code, when I initialize tempOriginal to 0x42, it works. |
|
|
|
HM,这是数字42眨眼的力量:我假设“不初始化”堆栈变量TimeIGIN偶然(或由于调试)可能有0的值。使用0x42只会帮助您在调试期间查看,在循环中的赋值期间,值会被更改(被重写)。我不认为初始化会改变程序逻辑中的任何东西,所以它也可能是以前工作过的。
以上来自于百度翻译 以下为原文 Hm, that's the power of the number 42 wink: I assumed that "not initializing" the stack variable tempOriginal by chance (or due to debugging) could have a value of 0. Using 0x42 should only help you to see during debugging, that the value changes (is overwritten) during assignment in the loop. I don't think the initialization changes anything in your program logic, so it probably also "worked" before. |
|
|
|
在下面的链接中,您可以看到变量TimigInal.HTPSP//Ibb. CO/JVCJ2W的值。
以上来自于百度翻译 以下为原文 Hi in the link below you can see the value of the variable tempOriginal. https://ibb.co/jvCJ2w |
|
|
|
42是对Unvives的回答。DATAS已经是一个指针,您不需要强制转换:PTR到PTR。这是一个粗略的想法。(由于复制粘贴,我删除了一些行)
以上来自于百度翻译 以下为原文 42 is the answer to the Universe. datas is already a pointer, you don't need the cast: ptr to ptr. Here's a rough idea. (I did delete some of the lines due to copy and paste) void function(unsigned char * Datas, unsigned int Num){ unsigned int templine=0; char *ptr; for(i=0;i ptr=Datas+templine; //split into two lines tempOriginal=*ptr; templine++; } |
|
|
|
|
|
|
|
如果你认为编译器做得不对,看看分解。
以上来自于百度翻译 以下为原文 If you think the compiler doesn't do things right, look at the disassembly. |
|
|
|
这是不合逻辑的吉姆。“空函数(un签署char * DATAS,未签名int num)”你漏了,“开始”。(有趣的Pascal笑话)什么是FUNC数据。接收?你把指针传递正确了吗?
以上来自于百度翻译 以下为原文 That is illogical Jim. "void function(unsigned char * datas,unsigned int num)" You missed out, "begin". (unfunny Pascal joke) What data is func. receiving? Did you pass the pointer correctly? |
|
|
|
大家好,我发现了这个问题。这是K40家族的勘误表。当您定义这样的const变量时,它不理解:const var []={0x00,0x00 }。为了解决这个问题,我需要向项目添加一个名为Poop-Up的ASCOMLY代码。代码必须有这样的行:谢谢大家!最好的问候,
以上来自于百度翻译 以下为原文 Hi everybody, I found the issue. It was an errata of the K40 family. It doesn't understand when you define a const variable like this: const var[]={0x00,0x00}. To resolve the issue I needed to add to the project an assambly code named power-up.as. The code must have this lines: #include GLOBAL powerup, start PSECT powerup, class="CODE", delta=1, reloc=2 powerup: BSF NVMCON1, 7 GOTO start end Thanks everybody! Best regards, |
|
|
|
编译器现在有能力为您这样做。阅读自带的自述文件。
以上来自于百度翻译 以下为原文 The compiler now has the capability to do that for you. Read the readme file that comes with it. |
|
|
|
因此,为什么我们通常会要求海报指定他们正在使用的图片。
以上来自于百度翻译 以下为原文 Hence why we usually ask posters to specify WHICH PIC they are using. |
|
|
|
只有小组成员才能发言,加入小组>>
5053 浏览 9 评论
1938 浏览 8 评论
1877 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3094 浏览 3 评论
请问电源和晶体值之间有什么关系吗?PIC在正常条件下运行4MHz需要多少电压?
2161 浏览 5 评论
602浏览 1评论
470浏览 1评论
有偿咨询,关于MPLAB X IPE烧录PIC32MX所遇到的问题
321浏览 1评论
PIC Kit3出现目标设备ID(00000000)与预期的设备ID(02c20000)不匹配。是什么原因
497浏览 0评论
404浏览 0评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-9-11 10:07 , Processed in 1.647560 second(s), Total 111, Slave 94 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191