What is data latching

What happens when data is written to LATCH?


I found the following in the data sheet PIC16F1947:

The status of the pins is read by reading the PORTB register, while the PORT latch is written by writing. All writes are read, modify, and write. Therefore, writing to a port means that the port pins are read, this value is changed and then written to the PORT data latch (LATB).

I'm a firmware developer with a background in computer science. I still struggle to understand electronics and logic at the hardware level. I only have the basic knowledge.

So I want to understand what happens when data is written to lock at the hardware level.

Thanks.

Reply:


Latch is a type of one-bit memory.

Let's use the picture in the manual:

When you write a bit to an I / O pin, you save that bit from the data bus in the data register (D flip-flop). When TRISx of this bit is 0, data from Q of the data register is in the I / O pin. Writing in LATx or PORTx is the same. See below in red:

On the other hand, reading LATx is different from reading PORTx.

When you read from LATx, you read what is in the data register (D-FlipFlop). See picture below in green:

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

PIC uses reads, changes, and writes to write operations. This can be a problem. So they use this shadow register to avoid this.






To avoid problems with reading, changing and writing, you should write to the entire port instead of setting or resetting individual bits in the port. An RMW problem can result in a bit not being set or another output going high, especially if the output pins are drawing or draining a lot of current.

Typically a "shadow register" is used. Put or put the bits in it and output them to the port to avoid RMW problems.

The problem is avoided with 18F-PICs by using a separate latch in which individual bits can be set and reset with impunity.





We use cookies and other tracking technologies to improve your browsing experience on our website, to show you personalized content and targeted ads, to analyze our website traffic, and to understand where our visitors are coming from.

By continuing, you consent to our use of cookies and other tracking technologies and affirm you're at least 16 years old or have consent from a parent or guardian.

You can read details in our Cookie policy and Privacy policy.