Generaly the problem occurs when you perform succesive RMW operations on the same port. Because of capacitance, both internal and external to the PIC, the pin may not have time to change states before the next instruction is executed. If (say) a pin is set low, and you perform a BSF on that pin, and then a BSF on another pin in the same port, the first pin may never get set. This is more likely at higher clock frequencies, but I have seen this at just 4Mhz, mainly because I was driving a power MOSFET which has considerable gate capacitance plus the track capacitance. A NOP between the instructions cured this behaviour, but knowing what I do now, I would use a shadow register everytime. Regards Mike Rigby-Jones > -----Original Message----- > From: Stan Ockers [SMTP:ockers@ANL.GOV] > Sent: Wednesday, May 12, 1999 2:56 PM > To: PICLIST@MITVMA.MIT.EDU > Subject: BCF and BSF on I/O ports > > Subject: Time: 8:03 > AM > BCF and BSF on I/O ports > 5/12/99 > Date: > I've been trying to understand this problem of using BCF or BSF with I/O > ports. I have yet to see a satisfactory explanation of why it should not > be done. I understand about read, modify write instructions and that > reading a I/O port reads the pin levels. You may not get what you expect > with > a read, but what do you expect? > > If a bit is an output, I expect to read whatever is latched because the > pin is connected to the latch. One explanation I saw read ; "but, what if > the latch is high and the pin is pulled low?". > Can someone explain how this is possible with out exceeding the 25 ma > sink limit of the pins? > I understand that a BCF on one output pin could affect the state on > another output pin if the pin level does not match the latched level but > normally this doesn't happen does it? > > I also read somewhere "inputs always read as 0". Should not the pin > level of inputs read high or low depending on whether the pin is being > pulled > high or low by an external source or sink? I understand that if you > change an input to an output, the level may not be what you want it to be. > But > surely you would realize that and modify the level accordingly. > > I've read a number of people mention that problems can be solved by using > a shadow register and that their programs started working when they did. > I just don't see why the problem should normally even come up. > > BTW can anyone point me to a list which shows which instructions are > read, modify write and which are not? > > Stan