Electrical – Read latch versus read pin (8051)

8051latchmicrocontrollerpins

As far as I understand, the 8051 microcontroller is able to read a pin

(1) by reading the actual pin, assuming the nFET is in cutoff (so a logic 1 is written before reading the pin)

(2) by reading the corresponding latch

Now is it true to assume that reading the latch only makes sense when using the pin as an output? And what are the advantages of reading the latch (which is used in e.g. read-write-modify instructions) instead of the actual pin?

Port 1 pin on a 8051

Best Answer

Reading the buffered output has an advantage when you want to do something like read-modify-write. E.g. you want to take the current value of the pin and logically AND it with some other value:

PIN = PIN & Value;

If the PIN is not buffered you won't be able to read it's value, as it is output, not input.