完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
大家好,我一直是PIC用户,但最近才开始使用PIC32。目前我正在开发一个PIC32 MX230F064 B项目。我使用MPLAB X 3.5和XC32 V1.42和代码配置器V3。我有一个简单的功能,试图通过IO引脚写HT1380。这不是中断程序。我有一个定时器中断,但似乎并没有改变结果。我的问题是一个变量意外地改变了它的内容。我用函数0x8e调用函数,用于“命令”。当我在调试过程中检查变量时,首先看到函数取值0x8e,然后在几个指令之后,在使用数据之前,值变为0x01。在调试过程中,我可以看到变量存储在“R04(CPU)”中。我可以把数据作为一个解决方案移动到一个新的变量,但我想知道发生了什么。我做错什么了?谢谢您!
以上来自于百度翻译 以下为原文 Hello everyone, I've been a long time PIC user but have only recently started using PIC32. Currently I'm using a PIC32MX230F064B on a project I'm developing. I'm using MPLAB X 3.5 and XC32 V1.42 and Code Configurator V3. I have a simple function that attempts to write a HT1380 through IO Pins. It's not on an interrupt routine. I've have a timer interrupt but it doesn't seem to change the results. My issue is that a variable changes its content unexpectedly. I call the function with the argument 0x8E for "command". When I check the variable during debugging I see that the function takes the value 0x8E at first, then after a few instructions the value changes to 0x01 before I get to use the data. During debugging I can see that the variable is stored in "r04 (CPU)". I can move the data to a new variable as a workaround, but I would like to understand what's going on. What am I doing wrong? Thank you! Clock_Write(0x8E, 0x00); // Write Protect OFF void Clock_Write (uint8_t command, uint8_t data) { unsigned char i; CLK_IO_SetLow(); CLK_SCK_SetLow(); CLK_CS_SetHigh(); CLK_IO_SetDigitalOutput(); for(i=0;i<8;i++) { CLK_SCK_SetLow(); if((command >> i) & 1) CLK_IO_SetHigh(); else CLK_IO_SetLow(); CLK_SCK_SetHigh(); } for(i=0;i<8;i++) { CLK_SCK_SetLow(); if((data >> i+1) & 1) CLK_IO_SetHigh(); else CLK_IO_SetLow(); CLK_SCK_SetHigh(); } CLK_IO_SetLow(); CLK_SCK_SetLow(); CLK_CS_SetLow(); return; } |
|
相关推荐
2个回答
|
|
请参阅XC32用户注册使用手册(特别是12.3个注册约定)。R4用于函数参数传递。你所看到的不是你的错误行为,也不是错误地被处理;你所看到的是预料之中的。如果你在代码中看到一个反汇编,你会更详细地了解R4是如何受到影响的。底线,当你编译,你的程序期待你的符号有一个值X,它不应该弄乱你…您的代码有一些问题,或者正在优化,导致您体验“意外”执行。总体上,确保优化关闭,因此您在C中编写的内容应该明确地发生。我高度怀疑XC32是造成你“简单”的日常悲伤。我的意思是,它可能被窃听,然后你写在MCHP的支持票上。最后,你编写C例程,把它交给编译器,然后以某种方式创建二进制文件,你可以通过MCHP工具闪存一些样式。这件事为什么发生的答案在于观察拆卸输出。你会看到R4***纵,因为它不会自动设置为任何东西…需要一个指令来影响可寻址存储器的任何区域,无论是RAM、ROM、寄存器等。
以上来自于百度翻译 以下为原文 Refer to XC32 user's manual for register usage (12.3 register conventions specifically). r4 is for function argument passing. What you are seeing is not your wrong doing, nor is this incorrectly being handled; what you are seeing is expected. If you look a the disassembly when you step through code, you will see more in detail how r4 is being affected. Bottom line, when you compile and your routine expects your symbol to have a value X, it shouldn't be messing up on you... You have some issue with your code or it is being optimized causing you to experience "unexpected" execution. Overall, make sure optimization is off so what you write in C should be happening explicitly. I highly doubt that XC32 is causing your "simple" routine grief. I mean, it's possible its bugged, then you write in support ticket to MCHP. In the end, you write C routine, hand it to compiler, then it creates binary file somehow, some fashion that you can flash via MCHP tools. The answer to WHY this stuff happens unexpectedly lies in observing the disassembly output. You will see r4 being manipulated, because it doesn't set itself to anything automatically... An instruction needs to be present to affect any area of addressable storage whether it be RAM, ROM, register, etc. |
|
|
|
你好,Cgiordan,非常感谢你的答复。我来这里上网是因为我没有主意,担心我做了一些根本错误的事情。我在代码中发现了一些错误,我认为这可能会导致编译器优化变量或重用它。我还认为,C代码指令的调试器可能会误导人。我会更加注意在拆卸视图上的调试。
以上来自于百度翻译 以下为原文 Hello Cgiordan, I really appreciate your thorough reply. I came here to check online because I was out of ideas and feared I was doing something fundamentally wrong. I found some mistakes in the code further down the line, I think maybe this lead to the compiler to optimize the variable or reuse it. I also think that maybe the debugger on the C coded instructions can be misleading. I'll pay more attention to debugging on the disassembly view. tl;dr; Thanks! |
|
|
|
只有小组成员才能发言,加入小组>>
5183 浏览 9 评论
2005 浏览 8 评论
1932 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3178 浏览 3 评论
请问电源和晶体值之间有什么关系吗?PIC在正常条件下运行4MHz需要多少电压?
2229 浏览 5 评论
739浏览 1评论
626浏览 1评论
有偿咨询,关于MPLAB X IPE烧录PIC32MX所遇到的问题
510浏览 1评论
PIC Kit3出现目标设备ID(00000000)与预期的设备ID(02c20000)不匹配。是什么原因
637浏览 0评论
535浏览 0评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-27 22:58 , Processed in 1.345385 second(s), Total 78, Slave 62 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号