完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
我的PIC32板包括2个LED。它们在引脚RB2和RB3上。它们与一个Pulp-电阻连接到VCC。现在我有一个问题编程它们。如果我使用端口寄存器,它们的行为非常怪异。PoBBITS.RB2=0;//这打开了.BoBBITS.RB3=0;//这打开了.PoBBITS.RB2=1;//这关闭了LeD1,但同时打开了Le2.PoBBITBES.RB3=1;//这关闭了Del2,但同时打开了LeD1。使用PORTBSET或PORTBCR寄存器。但是,使用锁存器等效物,一切都如预期的那样工作。数据表状态:对端口寄存器的写入实际上与写入LAT寄存器相同。对我来说这是没有意义的。
以上来自于百度翻译 以下为原文 My PIC32 board includes 2 LEDs. They are on pins RB2 and RB3. They are tied to VCC with a pullup-resistor. Now I have a problem programming them. If I use the PORT registers they behave very weird. PORTBbits.RB2 = 0; // This turns on BOTH. PORTBbits.RB3 = 0; // This turns on BOTH. PORTBbits.RB2 = 1; // This turns off LED1, but at the same time turns on LED2. PORTBbits.RB3 = 1; // This turns off LED2, but at the same time turns on LED1. Same if I use PORTBSET or PORTBCLR registers. But with the LATCH equivalents everything works as expected. The datasheet states: • A write to a PORT register is the effectively the same as a write to a LAT register. It doesn't make sense to me... |
|
相关推荐
3个回答
|
|
你所观察到的和预期的一样。当它说“写一个端口寄存器”时,它意味着写入整个寄存器,而不是写入一个单独的比特。即PORTB= 0x1234;相同的TelATB= 0x1234;但是,通过PoBBIT结构写入单个位不是一个简单的写。它有效地读取端口,修改一个位,然后重写整个寄存器。这意味着,如果读取的值与Labb寄存器中的值不一样,则除了目标位以外的位可以改变。
以上来自于百度翻译 以下为原文 What you observe is exactly as expected. When it says "A write to a PORT register", it means writing to the WHOLE register, not to an individual bit. i.e. PORTB = 0x1234; is identical to LATB = 0x1234; but, writing to a single bit via the PORTBbits structure is NOT a simple write. It effectively reads the port, modifies one bit, then rewrites the whole register. The implication of this is that if the value read is not the same as what is in the LATB register, then bits other than the target bit can change. |
|
|
|
谢谢。这对我来说还不清楚,但是,PurtBeSt和PotobCr寄存器呢?如果我理解正确,这些只会影响给定的比特,但是下面的命令也会影响两个LED:PoBbCr=4;PORTBCLR=8;PORTBSET=4;
以上来自于百度翻译 以下为原文 Thanks. This wasn't clear to me. But then, what about the PORTBSET and PORTBCLR registers? These should only affect the given bits, if I understand correctly. But the following commands also affect both LEDs: PORTBCLR = 4; PORTBCLR = 8; PORTBSET = 4; PORTBSET = 8; |
|
|
|
在内部,PIC仍在进行我所描述的读/修改/写操作。解决方案很简单。总是使用LAT寄存器来改变PIN STATUS。只在实际读取输入PIN的状态时才使用端口寄存器。
以上来自于百度翻译 以下为原文 Internally, the PIC is still doing the read/modify/write operation I described. The solution is easy. ALWAYS use the LAT register to change pin status. ONLY use the PORT register when you actually want to read the state of an input pin. |
|
|
|
只有小组成员才能发言,加入小组>>
5238 浏览 9 评论
2028 浏览 8 评论
1950 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3204 浏览 3 评论
请问电源和晶体值之间有什么关系吗?PIC在正常条件下运行4MHz需要多少电压?
2253 浏览 5 评论
776浏览 1评论
665浏览 1评论
有偿咨询,关于MPLAB X IPE烧录PIC32MX所遇到的问题
594浏览 1评论
PIC Kit3出现目标设备ID(00000000)与预期的设备ID(02c20000)不匹配。是什么原因
675浏览 0评论
575浏览 0评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-22 22:35 , Processed in 1.335898 second(s), Total 83, Slave 66 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号