Skip to main content
Corrected link
Source Link
Daniel Grillo
  • 7.7k
  • 18
  • 52
  • 70

Latch is a kind of memory of one bit.

Let's use the picture in manual:

Generic I/O Port Operation

When you write a bit in a I/O pin, you're storing this bit from Data Bus to the Data Register (D-FlipFlop). If TRISx of this bit is 0, so data from Q of the Data Register will be in the I/O pin. Write in LATx or PORTx is the same. See below in red:

Generic I/O Port Operation Write

On the other hand, read from LATx is different of read from PORTx.

When you're reading from LATx, you're reading what is in the Data Register (D-FlipFlop). See picture below in green:

Generic I/O Port Operation Read LATx

And when you read from PORTx, you're reading the actual I/O pin value. See below in blue:

Generic I/O Port Operation Read PORTx

PIC uses read-modify-write to write operations and this can be a problemproblem, so they use this shadow register to avoid it.

Latch is a kind of memory of one bit.

Let's use the picture in manual:

Generic I/O Port Operation

When you write a bit in a I/O pin, you're storing this bit from Data Bus to the Data Register (D-FlipFlop). If TRISx of this bit is 0, so data from Q of the Data Register will be in the I/O pin. Write in LATx or PORTx is the same. See below in red:

Generic I/O Port Operation Write

On the other hand, read from LATx is different of read from PORTx.

When you're reading from LATx, you're reading what is in the Data Register (D-FlipFlop). See picture below in green:

Generic I/O Port Operation Read LATx

And when you read from PORTx, you're reading the actual I/O pin value. See below in blue:

Generic I/O Port Operation Read PORTx

PIC uses read-modify-write to write operations and this can be a problem, so they use this shadow register to avoid it.

Latch is a kind of memory of one bit.

Let's use the picture in manual:

Generic I/O Port Operation

When you write a bit in a I/O pin, you're storing this bit from Data Bus to the Data Register (D-FlipFlop). If TRISx of this bit is 0, so data from Q of the Data Register will be in the I/O pin. Write in LATx or PORTx is the same. See below in red:

Generic I/O Port Operation Write

On the other hand, read from LATx is different of read from PORTx.

When you're reading from LATx, you're reading what is in the Data Register (D-FlipFlop). See picture below in green:

Generic I/O Port Operation Read LATx

And when you read from PORTx, you're reading the actual I/O pin value. See below in blue:

Generic I/O Port Operation Read PORTx

PIC uses read-modify-write to write operations and this can be a problem, so they use this shadow register to avoid it.

Source Link
Daniel Grillo
  • 7.7k
  • 18
  • 52
  • 70

Latch is a kind of memory of one bit.

Let's use the picture in manual:

Generic I/O Port Operation

When you write a bit in a I/O pin, you're storing this bit from Data Bus to the Data Register (D-FlipFlop). If TRISx of this bit is 0, so data from Q of the Data Register will be in the I/O pin. Write in LATx or PORTx is the same. See below in red:

Generic I/O Port Operation Write

On the other hand, read from LATx is different of read from PORTx.

When you're reading from LATx, you're reading what is in the Data Register (D-FlipFlop). See picture below in green:

Generic I/O Port Operation Read LATx

And when you read from PORTx, you're reading the actual I/O pin value. See below in blue:

Generic I/O Port Operation Read PORTx

PIC uses read-modify-write to write operations and this can be a problem, so they use this shadow register to avoid it.