完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
电子发烧友论坛|
嗨,我想写得更短一些。我发现有人使用那个代码:但是如果我这样做,编译器会给我一个错误!我不明白为什么。我可以用OSCON寄存器做同样的事情,但是用ChanSTAT寄存器,我不能。有人知道答案,或者知道写一个更好的方法。谢谢。我用的是PIC18F2580。
以上来自于百度翻译 以下为原文 Hi, I'd like to write CANSTATbits.OPMODE2=1; CANSTATbits.OPMODE1=1; CANSTATbits.OPMODE0=1; In a shorter way. I found that someone use that code: CANSTATbits.OPMODE=0b111; But if I do that the compiler give me an error! I can't understand why. I can make the same thing with the OSCON register, but with the CANSTAT one i can't. OSCCONbits.IRCF=0b111; //COorect CANSTATbits.OPMODE=0b100;//ERROR Someone know the answer, or know a better way to write that? Thanks. PS: I'm using a PIC18F2580 |
|
相关推荐
4个回答
|
|
|
|
|
|
|
|
|
检查XC8头文件包含/PIC18F2580.H,并搜索CabStATBIT。我想你会发现对于ICODE、EICODE和操作码的多位字段的定义都不见了。在不编辑原始标题的情况下修复它是很困难的。最简单的选择是使用移位和掩码来设置ChanSTAT SFR。但是,如果您想要多位字段定义,尝试:N.B。如果在“BADCANSTATBITS”补丁之前包含XC.H,这是不起作用的。我建议将它封装为“XCJPATHECH.H”,将其放入项目文件夹中,并将其包含在包含“XCJPATHED.H”*编辑A的“包含”和“XC.H.& GT”中,而不是“包含”和“XC.H.& GT”。标准(编译器提供)的头是一个大不不,因为它会打破,如果你升级编译器,可能会打破其他代码。
以上来自于百度翻译 以下为原文 Check the xc8 header file include/pic18f2580.h and search for CANSTATbits. I think you'll find the definitions for multi-bit fields for ICODE, EICODE and OPCODE are missing. Fixing it without editing the original header* is difficult. The easiest option is to use shifts and masks to set the CANSTAT SFR. However if you want the multibit-field definitions, try: //Override standard headers for CANSTATbits #define CANSTATbits badCANSTATbits #define CANSTATbits_t badCANSTATbits #include #undef CANSTATbits #undef CANSTATbits_t // Register: CANSTAT // my bitfield definitions // Register: CANSTAT extern volatile unsigned char CANSTAT @ 0xF6E; #ifndef _LIB_BUILD asm("CANSTAT equ 0F6Eh"); #endif // bitfield definitions typedef union { struct { unsigned EICODE0 :1; unsigned EICODE1 :1; unsigned EICODE2 :1; unsigned EICODE3 :1; unsigned EICODE4 :1; unsigned OPMODE0 :1; unsigned OPMODE1 :1; unsigned OPMODE2 :1; }; struct { unsigned :1; unsigned ICODE1 :1; unsigned ICODE2 :1; unsigned ICODE3 :1; }; struct { unsigned EICODE :5; unsigned OPMODE :3; }; struct { unsigned :1; unsigned ICODE :3; }; } CANSTATbits_t; extern volatile CANSTATbits_t CANSTATbits @ 0xF6E; N.B. this does not work if you include xc.h before the 'badCANSTATbits' patch. I suggest wrapping it up as "xc_patched.h", putting it in the project folder and including it instead of #include * Editing a standard (compiler supplied) header is a big No-No, as it will break if you upgrade the compiler and may break other code. |
|
|
|
|
|
如果你相信多位字段应该存在,请在你的原始代码(在应用伊恩的优秀建议之前)记录一张支持票来演示这个问题。
以上来自于百度翻译 以下为原文 And if you believe the multi-bit fields should be present, please log a support ticket including your original code (before applying Ian's excellent suggestion) to demonstrate the problem. |
|
|
|
|
|
第二个定义应该是:加1的支持票——从数据表中的寄存器定义很明显,ChanSTAT中的位是分组的,不是单独的标志。
以上来自于百度翻译 以下为原文 The second #define should be: #define CANSTATbits_t badCANSTATbits_t +1 for putting in a support ticket - its pretty obvious from the register definition in the datasheet that the bits in CANSTAT are grouped and aren't individual flags. |
|
|
|
|
只有小组成员才能发言,加入小组>>
MPLAB X IDE V6.25版本怎么对bootloader和应用程序进行烧录
473 浏览 0 评论
5793 浏览 9 评论
2334 浏览 8 评论
2224 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3530 浏览 3 评论
1124浏览 1评论
有偿咨询,关于MPLAB X IPE烧录PIC32MX所遇到的问题
1095浏览 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 04:42 , Processed in 0.597149 second(s), Total 76, Slave 59 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191

淘帖
932