Be aware that if you are using an instruction to do a read/modify/write operation on a port then you need to have at least 1 instruction between this instruction and the previous instruction that wrote to the same port. The reason is that the write to the port is done at the tail end of the operation, and if you then do a bit operation (this is a read/modify/write type instruction) then the read of the port status is done very early in the operation. It may be that you have problems because the level on the pin has not had sufficient rise time to get to the state you expect on this next instruction. Also be aware that when an I/O port is read, the actual state of the pin is read, not the state of the output flip flop. The result of this is if you do a read/modify/write operation on the port, if you have the base of a transistor directly attached to the port, then the pin may not get to a high enough voltage to register as a "1" state.