I am currently working on a PIC18F and I wonder what the difference is between a PORT
and a LAT
because looking at the documentation of the PIC18F they both do the same thing.
Asked
Active
Viewed 550 times
1

Mike
- 4,041
- 6
- 20
- 37
1 Answers
1
A write to the PORTx
register writes the data value to the port latch.
A write to the LATx
register writes the data value to the port latch.
A read of the PORTx
register reads the data value on the I/O pin.
A read of the LATx
register reads the data value on the port latch.
Use LATx
: to write to an output pin
Use PORTx
: to read an input pin
For all PICs with LATx
registers, all INPUT must be from PORTx
and all OUTPUT should be to LATx
, which totally avoids the problem of flipping bits when you write to a single bit of the port.

Mike
- 4,041
- 6
- 20
- 37
-
1thanks you for explanation – Celle qui parle aux chiens Oct 26 '21 at 11:37