Difference between PORT and LATCH on PIC 18F

前端 未结 8 819
南旧
南旧 2020-12-04 22:02

I already read the datasheet and google but I still don\'t understand something.

In my case, I set PIN RC6 of a PIC18F26K20 in INPUT mode:

TRI

8条回答
  •  难免孤独
    2020-12-04 22:44

    Here's a useful summary from the datasheet.

    11.2.3 LAT Registers
    The LATx register associated with an I/O pin eliminates the problems that could occur with read-modify-write instructions. A read of the LATx register returns the values held in the port output latches, instead of the values on the I/O pins. A read-modify-write operation on the LAT register, associated with an I/O port, avoids the possibility of writing the input pin values into the port latches. A write to the LATx register has the same effect as a write to the PORTx register.

    The differences between the PORT and LAT registers can be summarized as follows:

    • 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 held in the port latch.

提交回复
热议问题