完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
扫一扫,分享给好友
大家好,我想弄清楚在下面的代码中,什么是PrcBITS.RC0:Oy定义开关PtcBITS.RC0i,理解您定义的RC0作为输入,但它与PORTC=0B000 000 01基本相同吗?谢谢你的帮助。
以上来自于百度翻译 以下为原文 Hello all, I was trying to figure out what PORTCbits.RC0 stands for in the below code: #define SWITCH PORTCbits.RC0 I understand that your defining RC0 as a input but is it the same as PORTC = 0b00000001 basicly? thanks for the help. |
|
相关推荐
15个回答
|
|
定义是一个编译器指令,它允许你将一个东西替换为另一个(通常使代码更容易理解)。在这里,你可以通过名称开关引用PORTC寄存器的RC0位,写起来更容易一些,也许更容易理解D的功能。ATA在RC0上表示。这是一个简单的文本替换在预处理器。请参阅5.5.2节预处理器指令和表5-16预处理器指令在XC8用户指南的快速解释。TISISC寄存器确定I/O引脚是否为输入或输出模式。NOPE,它简单地将PORTC寄存器中的值设置为0x01(0B000 000 01)。我认为需要一些基本的C指令,再加上PIC控制器如何工作的一些研究。
以上来自于百度翻译 以下为原文 #define is a compiler directive that allows you to substitute one thing for another (usually to make the code easier to understand). Here it allows you to refer to the RC0 bit of the PORTC register by the name SWITCH, a little easier to write and maybe easier to understand what the function of the data at RC0 represents. It is a simple text substitution in the preprocessor. See SECTION 5.14.2 PREPROCESSOR DIRECTIVES and Table 5-16 PREPROCESSOR DIRECTIVES in the XC8 user guide for a quick explanation. No it does not. The TRISC register determines if an I/O pin is input or output mode. Nope, this simply sets the value in the PORTC register to 0x01 (0b00000001). I think some basic c instruction is needed plus a little research on how the pic controllers work.... |
|
|
|
RoC0=1;基本相同的ASRC0=1;OrPoC C=0B00 0 000 01;然而,这将假定编译器优化它。PIC具有位运算码。这意味着它可以设置或清除一个比特,而不需要读取ReGISER,掩蔽它,然后把它写回去。它可以用一个OP代码来完成。
以上来自于百度翻译 以下为原文 PORTCbits.RC0 = 1; is Basicly same as RC0 = 1; or PORTC |= 0b00000001; however that would assume the compiler optimizes it. the PIC has bit op-codes. that means it can set or clear a single bit without reading the Regiser, masking it, thne writing it back. and it can do it with a single op-code. |
|
|
|
但也请注意,您不应该写入该位,只使用它来读取。如果您想写入RC0 PIN,请使用:LabcTysLATC0=1;这避免了“读取-修改-写入”问题,这可能在您最不期望的时候引起神秘的问题。
以上来自于百度翻译 以下为原文 But also notice, you should NOT be writing to that bit, only use it for reading. If you want to write to the RC0 pin, use: LATCbits.LATC0 = 1; This avoids "Read-Modify-Write" problems, which can cause mysterious issues when you least expect it. |
|
|
|
PrcBITS.RC0用于读取端口C的引脚数0(端口C的最小有效位-LSB)。
以上来自于百度翻译 以下为原文 PORTCbits.RC0 is used for read the pin number 0 of Port C (Least Significance Bit - LSB of Port C). |
|
|
|
好了,谢谢各位,所以基本上定义开关PtcBITS.RC0与定义开关PORTC=0B000 00 001正确吗?
以上来自于百度翻译 以下为原文 Okay thanks guys, so basicly #define SWITCH PORTCbits.RC0 is the same as #define SWITCH PORTC = 0b00000001 correct? |
|
|
|
不,您可以读取PoCtBys.RC0为零或一个,并且还可以在不改变POTC的其他引脚(除了RMW问题的情况下)向PIN写入一个或0个。PORTC=0B000 0 0 01是一个赋值语句,它将写入整个8位端口。所以,首先,你可以有int MyVa=开关,或者你可以有开关=1或开关=0。还要知道“开关”是C.的保留字。
以上来自于百度翻译 以下为原文 No, you may read PORTCbits.RC0 as a zero or one, and you can also write a one or zero to the pin without changing the other pins of PORTC (except for RMW issues). PORTC = 0b00000001 is an assignment statement that will write to the entire 8 bit port. So for the first, you could have int MyVar = SWITCH, or you could have SWITCH = 1 or SWITCH = 0. Also be aware that "switch" is a reserved word in C. |
|
|
|
不正确。你知道吗?这不是一个可执行的声明。
以上来自于百度翻译 以下为原文 Incorrect. Do you understand that #define is just defining a text substitution? It is not an executable statement. |
|
|
|
它是用一个单一的操作码(指令)完成的,但是阅读和修改也在那里。
以上来自于百度翻译 以下为原文 It is done with(in) a single opcode/(instruction), but the reading and modifying is there anyway. |
|
|
|
正如其他人所说的,这是不正确的。PrtcBITS.RC0是PORTC寄存器的位0,它是该端口的PIN 0。它只是一个8位宽的POTC寄存器的一位。定义是一种给别名提供别名的方法;也就是说,允许使用PosicTwitter。当然,人们希望使用一个更有意义的名字,比如StupLoButt;
以上来自于百度翻译 以下为原文 As others have said, that is incorrect. PORTCbits.RC0 is bit 0 of the PORTC register, which is pin 0 of that port. It is just a single bit of the 8-bit wide PORTC register. The #define is a way to give an alias to something; that is, #define SWITCH PORTCbits.RC0 allows you to use the name SWITCH wherever PORTCbits.RC0 is used. Perferably, one would want to use a more meaningful name like STOP_BUTTON; e.g. #define STOP_BUTTON PORTCbits.RC0 if (STOP_BUTTON == 0) { // code to execute when Stop button on RC0 is pressed } which is identical to this if (PORTCbits.RC0 == 0) { // code to execute when Stop button on RC0 is pressed } |
|
|
|
正如其他人所说的,肯定是不正确的。你知道(=)和=(相等)之间的区别吗?禁止编译器优化,对于读取,它可以被认为是等价的。
以上来自于百度翻译 以下为原文 As others have said, definately incorrect. Do you know the difference between = (asignment) and == (equality)? Barring compiler optimisations, for reads it could be considered to be equivalent to #define SWITCH (!!(PORTC & 0b00000001)) |
|
|
|
正如其他人所说的,肯定是不正确的。你知道(=)和=(相等)之间的区别吗?除了编译器优化,对于阅读,它可以被认为是等价的,谢谢大家,这就是我想知道的。我想我没把这个问题说得很好。但是为什么呢!???不!代表否定!这会是双重否定吗?
以上来自于百度翻译 以下为原文 As others have said, definately incorrect. Do you know the difference between = (asignment) and == (equality)? Barring compiler optimisations, for reads it could be considered to be equivalent to #define SWITCH (!!(PORTC & 0b00000001)) Thanks everyone, this is what I was wondering. I guess I didn't word the question very well. But why the !! ? Doesn't ! stand for negation so !! would that would be a double negation? |
|
|
|
这是第一个有趣的把戏!将“任何不为零”转换为逻辑零点,“任意为零”转换为逻辑非零;第二!再次反转,所以基本上你和转换“算术”=“0”到逻辑“真”和“0”到“假”,两者都更适合当需要1位宽值(甚至更大)时。
以上来自于百度翻译 以下为原文 It's a funny trick the 1st ! converts "whatever not zero" to logical zero, and "whatever is zero" to logical non-zero; the 2nd ! inverts this again. So basically you and up with converting "arithmetic != 0" to logical "true" and "0" to "false", both more suitable when a 1bit wide value is needed (or even larger). |
|
|
|
实际上,在这种情况下,双逻辑否定是非必要的,因为它是位0;也就是说,条件测试是“0”(false)或“1”(true)。
以上来自于百度翻译 以下为原文 Actually in this case the double logical negation is _not_ necessary since it is bit 0; that is, the conditional test is either "0" (false) or "1" (true). |
|
|
|
它是用一个单一的操作码(指令)完成的,但是读和修改在那里。RMW操作码与RMW代码不一样。虽然他们确实有一些相同的问题。但是RMW操作码是原子的,执行速度更快。
以上来自于百度翻译 以下为原文 It is done with(in) a single opcode/(instruction), but the reading and modifying is there anyway. A RMW opcode is not the same as RMW code. Though they do share some of the same issues. But a RMW opcode is atomic and executes quicker. |
|
|
|
事实上,我基本上从来没有感觉到这样做的必要性:即使分配给单位位字段(也就是说),我只是通过分配原始值来合理地工作。
以上来自于百度翻译 以下为原文 More actually I basically almost never felt the need for that: even when assigning to single bit bitfields (to say) I got it reasonably working by just assigning the original value. |
|
|
|
只有小组成员才能发言,加入小组>>
5166 浏览 9 评论
2000 浏览 8 评论
1928 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3174 浏览 3 评论
请问电源和晶体值之间有什么关系吗?PIC在正常条件下运行4MHz需要多少电压?
2226 浏览 5 评论
734浏览 1评论
615浏览 1评论
有偿咨询,关于MPLAB X IPE烧录PIC32MX所遇到的问题
506浏览 1评论
PIC Kit3出现目标设备ID(00000000)与预期的设备ID(02c20000)不匹配。是什么原因
631浏览 0评论
528浏览 0评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-24 19:04 , Processed in 1.537114 second(s), Total 103, Slave 87 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号