完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
电子发烧友论坛|
大家好,我这里有一个简单的代码。我要读无符号char UART1YRX缓冲器[80 ],缓冲器从0x9EC开始,它是:在这里我的函数读取缓冲器,在这里我称为WIT-PTR值0x9ED:为什么工作而不是???????
以上来自于百度翻译 以下为原文 Hi to all, I have here simple piece of code. I'm going to read unsigned char UART1_RxBuffer[80], buffer starts at 0x9EC and it is: 0x9EC -> 0x52 (Start header char) 0x9ED -> 0x03 (Header type) 0x9EE -> 0x03 (Number of bytes LSB) 0x9EF -> 0x00 (Number of bytes MSB) 0x9F0 -> 0x01 (message byte 1) 0x9F1 -> 0x00 (message byte 2) 0x9F2 -> 0x00 (message byte 3) 0x9F3 -> 0x04 (checksum LSB) 0x9F4 -> 0x12 (checksum MSB) Here my function to read buffer where I call wit ptr value 0x9ED: void ManageHeaderType (unsigned char *ptr) { unsigned char *ptr_chk, *dummy_ptr; unsigned char HdrType; unsigned int l_NumOfBytes; unsigned char CK_A, CK_B = 0; unsigned int i, CheckSum; unsigned int *int_ptr; unsigned int brody; ptr_chk = ptr; HdrType = *ptr++; // it correctly reads 0x03 // reading unsigned int using unsigned char pointer l_NumOfBytes = *(unsigned int *)(ptr); // it correctly reads 0x0003 dummy_ptr = ptr; dummy_ptr += l_NumOfBytes+2; // ptr value is 0x9F3 int_ptr = (unsigned int *)dummy_ptr; // int_ptr value is 0x9F3, MPLAB X correctly shows *int_ptr = 0x1204 in tooltip CheckSum = *(unsigned int *)(dummy_ptr); // now CheckSum contents is 0x09F3 brody = *int_ptr; // here value of brody is 0x09F3 Why l_NumOfBytes = *(unsigned int *)(ptr); works while CheckSum = *(unsigned int *)(dummy_ptr); and brody = *int_ptr; not????? |
|
相关推荐
1个回答
|
|
|
OK -不应该是这样的,但是-IIr- 16位PICS希望整数驻留在偶数地址上(9F3是奇数!)这可能是造成这种不良行为的原因。我希望得到更好的结果微笑:
以上来自于百度翻译 以下为原文 OK - shouldn't be like that. But - IIRC - the 16-Bit PICs expect integers to reside on even addresses (9F3 is odd!) - which might be a reason for this mi***ehavior. I'd expect CheckSum = *dummy_ptr + (*(dummy_ptr+1) << 8); to yield better results Smile: |
|
|
|
|
只有小组成员才能发言,加入小组>>
MPLAB X IDE V6.25版本怎么对bootloader和应用程序进行烧录
475 浏览 0 评论
5794 浏览 9 评论
2334 浏览 8 评论
2224 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3530 浏览 3 评论
1125浏览 1评论
有偿咨询,关于MPLAB X IPE烧录PIC32MX所遇到的问题
1098浏览 1评论
我是Microchip 的代理商,有PIC16F1829T-I/SS 技术问题可以咨询我,微信:A-chip-Ti
873浏览 1评论
MPLAB X IDE V6.25版本怎么对bootloader和应用程序进行烧录
475浏览 0评论
/9
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2025-12-2 17:45 , Processed in 0.779748 second(s), Total 74, Slave 57 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191

淘帖
1970