关于PIC单片机“读-修改-写”的相关说明
,不管在这个引脚上是否有电压。This is an exception to the normal rule that the pin state is always read. 通常情况下这些管脚始终都是作输入的,不会有这种现象。You can still configure an anolog pin as an output in the TRIS register, and drive the pin high or low by writing to it, but you will always read a zero. 你也可以通过配置TRIS寄存器来改变这些模拟输入管脚作为输出,并且通过写寄存器驱动这些引脚为高或低,但是你将一直读到“0”。Therefore if you execute a Read-Modify-Write instruction (see previous question) all analog pins are read as zero, and those not directly modified by the instruction will be written back to the port latch as zero. 所以当你执行一个“读-修改-写”指令(见前一个问题),所有的模拟管脚读为“0”,并且在没有被指令直接修改的情况下,将端口锁存器的值改为“0”。A pin configured as analog is expected to have values that may be neither high nor low to a digital pin, or floating. Floating inputs on digital pins are a no-no, and can lead to high current draw in the input buffer, so the input buffer is disabled. 一个被配置为模拟口的管脚将被认为有一个可能既非高也非低的值,或者是浮空的,相对于数字口而言。在数字口上的输入也是一种非高非低的状态,并且能够导致输入缓冲器的大电流泄漏,所以输入缓冲器被禁止。
Another case where a RMW instruction may seem to change other pin values unexpectedly can be illustrated as follows: 另一种情况下,“读-修改-写”指令好像是违背期望地修改了其他引脚的值,一般能被描述如下:Suppose you make PORTC all outputs and drive the pins low. 假设你把PORTC全作为输出并驱动所有管脚为低。On each of the port pins is an LED connect to ground, such that a high output lights it. Across each LED is a 100uF capacitor. 在这个端口的每个管脚上有一个LED连到地,这样输出高时将点亮LED。并在每一个LED上有一个100uF的电容。Lets also suppose that the processor is running very fast, say 20MHz. 让我们也假设处理器运行得非常快,比如说20MHz。Now if you go down the port setting each pin in order; BSF PORTC,0 then BSF PORTC,1 then BSF PORTC,2 and so on, you may see that only the last pin was set, and only the last LED actually turns on. 现在如果你清端口后依次去置位引脚,如BSF PORTC,0 然后BCF PORTC,1 接着BCF PORTC,2 这样下去,你将看到只有最后的一个管脚被真正置位了,只有一个LED点亮。This is because the capacitors take a while to charge. As each pin was set, the pin before it was not charged yet and so was read as a zero. 这是因为电容需要时间来充电。当一个管脚被置位时,它前面被置位的那个管脚还没有充电完全,所以读到的还是“0”。This zero is written back out to the port latch (RMW, remember) which clears the bit you just tried to set the instruction before. 这个“0”将被写回端口锁存器(读-修改-写),清掉前面你刚用指令来置“1”的那个位。This is usually only a concern at high speeds and for successive port operations, but it can happen so take it into consideration. 这种情况通常只发生在高速并且连续的端口操作中,但这的确会发生,所以要在设计中考虑。
另,明显错误的设计,导致的“读-修改-写”问题,不再赘述。
PIC单片机读修改 相关文章:
- Windows CE 进程、线程和内存管理(11-09)
- RedHatLinux新手入门教程(5)(11-12)
- uClinux介绍(11-09)
- openwebmailV1.60安装教学(11-12)
- Linux嵌入式系统开发平台选型探讨(11-09)
- Windows CE 进程、线程和内存管理(二)(11-09)
