1

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.

Mike
  • 4,041
  • 6
  • 20
  • 37

1 Answers1

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