完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
我使用的是PIC32 MX CPU,我使用C端口的低字节将数据写入总线。但我想在端口C上使用其他可用的PIN。是否有掩码写入只更新较低的字节?谢谢!古瑟
以上来自于百度翻译 以下为原文 I am using a PIC32MX CPU and I am using the low byte of port C to write data to a bus. But I want to use the other available pins on port C. Is there a masked write to update just the lower byte? Thanks! Guenther |
|
相关推荐
15个回答
|
|
|
|
|
|
有一个特殊的寄存器LATXIN。当你给它写时,它反转了写TOTO一个的所有比特。所以你可以做这样的事情:
以上来自于百度翻译 以下为原文 There is a special register LATxINV. When you write to it, it inverts all bits which are written to to one. So you can do something of that sort: void WriteBus(char new_state_of_the_bus) { static char previous_state_of_the_bus = 0; LATDINV = previous_state_of_the_bus ^ new_state_of_the_bus; previous_state_of_the_bus = new_state_of_the_bus; } |
|
|
|
LATC^=(NeXiLuxByth-^ LATC)和0xFF;
以上来自于百度翻译 以下为原文 LATC ^= (new_low_byte ^ LATC) & 0xFF; |
|
|
|
LATC^=(NeXixLuxByth-LATC)和0xFF;或者,因为这是针对PIC32 LATCVI=(NeXiLuxByth-^ LATC)和0xFF;
以上来自于百度翻译 以下为原文 LATC ^= (new_low_byte ^ LATC) & 0xFF; Or, as this is for a Pic32 LATCINV=(new_low_byte ^ LATC) & 0xFF; |
|
|
|
数据是一个简单的像素LCD。我刚刚在宏中使用了一个“LATC=数据”,用于显示的所有写入。我希望我能避免额外的阅读和额外的代码混合在上面的位。感谢优秀的例子!/古恩瑟
以上来自于百度翻译 以下为原文 The data is going to a simple pixel LCD. I just had a 'LATC = data' in a macro used for all writes to the display. I was hoping I can avoid the extra read and extra code to blend in the upper bits. Thanks for the excellent examples! /Guenther |
|
|
|
我运行了一个快速测试整个屏幕200次:LATC=数据;24秒StLC^=(数据^ LATC)和0xFF;32秒LATCVI=(数据^ LATC)和0xFF;28秒/ GueNETH。
以上来自于百度翻译 以下为原文 I ran a quick test painting the whole screen 200 times: LATC = data; 24 seconds LATC ^= (data ^ LATC) & 0xFF; 32 seconds LATCINV=(data ^ LATC) & 0xFF; 28 seconds /Guenther |
|
|
|
|
|
|
|
Hi,PIC32 MX微控制器在端口控制寄存器中有额外的硬件门,以便能够对寄存器中的一个比特进行原子更新。对于不同的操作有3组门:或门,在外围SFR寄存器XOR门中设置任何位选择,以反转A s。IMPARAR选择位和门来清除寄存器中的任何位选择。然而,设置一些位和清除其他位来更新寄存器的任意部分,将需要进行2次写入操作。事实上,这不仅对端口控制寄存器,几乎每一个外围SFR寄存器都是如此。具有这些位操作寄存器。与端口锁存寄存器:LATC,有:LATCLR、LATCSET和LATCVIN,它们都有独立的总线地址。因为PIC32 CPU是流水线的,而PIC32微控制器中的总线系统具有桥路,并且可能有不同的操作频率,PIC32。无法读取SFR寄存器,计算更新并将结果存储在同一指令中。此外,阅读SFR寄存器需要更长的时间比写作。(PIC32 MZ在访问SFR寄存器时甚至比MX还要慢)所有上述示例代码都可以在不干扰寄存器的其他部分中的内容的情况下工作,但是引用寄存器的以前内容的所有代码都必须进行读修改写操作,这不是原子的,我们将更多的时间比需要…你可以尝试:问候,Mysil
以上来自于百度翻译 以下为原文 Hi, PIC32MX microcontrollers have extra hardware gates in in Port Control registers, to be able to do atomic updates to a selection of bits in the register. There are 3 sets of gates for different operations: OR gates, to SET any selection of bits in the peripheral SFR register, XOR gates, to INVert a similar selection of bits, and gates to CLeaR any selection of bits in the register. However, Setting some bits, and Clearing other bits, to update an arbitrary part of the register, will take 2 write operations. In fact, this is not only for port control registers, nearly every peripheral SFR register have these bit manipulation registers. Together with Port Latch register: LATC, there are: LATCCLR, LATCSET and LATCINV, they all have a separate bus address. Since the PIC32 CPU is pipelined, and the bus system in PIC32 microcontrollers have bridges, and possibly different operating frequency, PIC32 cannot Read a SFR register, calculate a update and store the result in the same instruction. Also, Reading a SFR register take longer time than writing. (PIC32MZ is even slower than MX in accessing SFR registers.) All of the above example codes, may work without disturbing contents in other parts of the register, but all codes that refer to previous content of the register, will have to do a Read-Modify-Write operation, that is not atomic, and will use more time than needed.. You may try this: LATCSET = new_low_byte & 0xFF; LATCCLR = (~new_low_byte) & 0xFF; Regards, Mysil |
|
|
|
诺斯盖尔,你的版本计时了54秒。主要是因为我想-调用子程序。我可以改变你的例子,不要使用子程序。但最后还有额外的任务。
以上来自于百度翻译 以下为原文 NorthGuy, your version clocked 54 seconds. Mostly due - I think - to the subroutine call. I could change your example to not use a subroutine. But there is still this extra assignment at the end. /Guenther |
|
|
|
当然,您需要删除函数调用——这需要很长时间,也会阻止编译器在寄存器中保持“PyviuyBuSuthStand”。在删除函数调用之后,如果编译器自己无法理解它,则可以给出“PrviviuBuSyStand”变量“寄存器”指定。保持“PyviuyBuSuthStand”只需要在寄存器(新到先前)之间进行一次移动。CPU暂停,因为它不能缓存)加上一个额外的“& 0xFFF”操作。
以上来自于百度翻译 以下为原文 Of course, you need to remove the function call - it takes long time, and also precludes the compiler from keeping the "previous_bus_state" in a register. After removing the function call you can give the "previous_bus_state" variable a "register" designation if the compiler cannot figure that out by itself. Maintaining the "previous_bus_state" requires only one move between registers (new to previous). Reading LATC requires SFR reading (which causes a CPU stall because it cannot be cached) plus an extra "&0xff" operation. |
|
|
|
LATCSET = NexyLuxByth&0xFF;LATCLR= =(~NeXiLuxByb)和0xFF;…用我的测试花费了32秒。
以上来自于百度翻译 以下为原文 LATCSET = new_low_byte & 0xFF; LATCCLR = (~new_low_byte) & 0xFF; ...took 32 seconds with my test. /Guenther |
|
|
|
或者一个更好的解决方案,或者两者都应该编译成一个简单的字节存储。在模拟器和实际硬件中,这都不干扰端口的其余部分。编辑:第一个版本的地址是MZ,对于MX,它是用于LATC的0xBF8660A0。可能第二个版本更通用,因为第一个版本只与BYTE0一起工作,因为对齐问题(不能指定未对齐的地址)和不可移植性。
以上来自于百度翻译 以下为原文 Or an even better solution //Global var uint8_t __attribute__((section("sfrs"),address(0xBF860230))) LATCLOBYTE; void SetLATCLoByte(uint8_t newvalue) { LATCLOBYTE=newvalue; }ortypedef struct __attribute__((packed)) { uint8_t BYTE0; uint8_t BYTE1; uint8_t BYTE2; uint8_t BYTE3; } SFRBYTE; extern volatile SFRBYTE LATCBytes __asm__ ("LATC") __attribute__((section("sfrs"))); void SetLATCLoByte(uint8_t newvalue) { LATCBytes.BYTE0=newvalue; } Both the above should compile to a simple byte store. This is confirmed to not disturb the rest of the port, both in the simulator and on actual hardware. Edit:- The address for the first version is for an MZ, for MX it is 0xBF8660A0 for LATC. Probably the second version is more universal, as the first version only works with BYTE0 due to alignment issues (you cannot specify an un-aligned address) and non-portability. |
|
|
|
当然,我用我的帖子把这个线程移到错误的方向:(完全是我的错)。
以上来自于百度翻译 以下为原文 Of course. I derailed the thread into the wrong direction with my post :( Totally my fault. |
|
|
|
使用“影子寄存器”怎么样?这将消除读取寄存器的需要——只需要一个写入来更新,并且您总是可以同时更新整个端口。改变的比特,改变的,不改变的。
以上来自于百度翻译 以下为原文 How about using a "Shadow Register"? This would eliminate the need to read the register - only a write is needed to update and you can always update the entire port at once. Bits that change - change and those that don't - don't. |
|
|
|
那也行得通。但会采取更多的指令周期。
以上来自于百度翻译 以下为原文 That would work too. But would take more instruction cycles. |
|
|
|
只有小组成员才能发言,加入小组>>
5212 浏览 9 评论
2019 浏览 8 评论
1944 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3192 浏览 3 评论
请问电源和晶体值之间有什么关系吗?PIC在正常条件下运行4MHz需要多少电压?
2246 浏览 5 评论
760浏览 1评论
647浏览 1评论
有偿咨询,关于MPLAB X IPE烧录PIC32MX所遇到的问题
567浏览 1评论
PIC Kit3出现目标设备ID(00000000)与预期的设备ID(02c20000)不匹配。是什么原因
659浏览 0评论
557浏览 0评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-12 10:11 , Processed in 2.119887 second(s), Total 105, Slave 88 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号