How to avoid the Read-Modify-Write problem in P16 (or P12 or P10) Pic's.
1. Problem
There are no "LAT" registers present in the P16 etc familly, so the solution sugested in article
The read-modify-write problem (and how to avoid it).
can not be used.
2. Solutions.
There are 2 possible solutions to avoid the RMW problem in P16 Pic's:
A. Wait a while after setting the port values until the output voltages are stabilised, so
instead of
PortB := 0;
PortB.2 := 1;
PortB.4 := 1;
do
PortB := 0;
Delay...
PortB.2 := 1;
Delay...
PortB.4 := 1;
Delay...
The problem here is that the "delay" time needed depends on the capacitive load on the port used.
B. Make your own "Lat" variable, so
instead of
PortB := 0;
PortB.2 := 1;
PortB.4 := 1;
do
var LatB_ : byte;
...
LatB_ := 0; // give "LatB" its initial value
PortB := LatB_; // copy its contents to portB
LatB_.2 := 1; // Use LatB in stead of PortB, the actual state of PortB is not used any more
PortB := LatB_; // Copy again into PortB
LatB_.4 := 1;
PortB := LatB_;
This method works in the same manner as the Lat register in the P18 family works.
The second method is always reliable.
-------------------------------------------