Datasheet
PIC14000
DS40122B-page 36 Preliminary 1996 Microchip Technology Inc.
5.4.2 SUCCESSIVE OPERATIONS ON I/O
PORTS
The actual write to an I/O port happens at the end of an
instruction cycle, whereas for reading, the data must be
valid at the beginning of the instruction cycle.
Therefore, care must be exercised if a write operation
is followed by a read operation on the same I/O port.
The sequence of instructions should be such to allow
the pin voltage to stabilize before the next instruction
which causes that port to be read into the CPU is
executed. Otherwise, the previous state of that pin may
be read into the CPU rather than the new state. When
in doubt, it is better to separate these instructions with
a NOP or another instruction not accessing this I/O
port.
FIGURE 5-13: SUCCESSIVE I/O OPERATION
Q1 | Q2 | Q3 | Q4
PC PC + 2
PC + 1 PC + 3
MOVWF PORTC
Write to PORTC
MOVF PORTC, W
Read PORTC
NOP
NOP
RC<x>
Port pin sampled
here
Execute MOVWF
PORTC
Pin values
Execute MOVF
PORTC, W
Execute NOP
Example showing write to PORTC followed by immediate read. Some delays in settling may cause “old”
Port data to be read, especially at higher clock frequencies. Data setup time = (0.25 Tcyc- Tpd), where
Tcyc = instruction cycle time.
Q1 | Q2 | Q3 | Q4 Q1 | Q2 | Q3 | Q4 Q1 | Q2 | Q3 | Q4