Re: What is the Latch State of a Port?
All digital I/O pins have output Latches, PC with parallel Port ( Centronics printer interface),
Atmel microcontroller, PIC microcontroller, or anything else.
Output Latch is a FlipFlop that is Set or Cleared, to control and keep the Output state of each Pin.
Output Latches are organised into a register, with one bit for each pin of a Port.
The register will be written when addressed by the peripheral address and data bus.
However, Not all devices are able to Read the state of the output Latch register
when the Pin is configured as Input.
In Old PIC devices, there is no address for the LATch register in the SFR memory map.
Writing to the PORT register address will go into the LATCH flip-flops.
Reading from the PORT register address will however Read from the digital Input buffers,
these are different circuits, that are connected to the same pins.
When a Port have some pins configured as Inputs, and other pins as Output,
this may have some confusing effects, with some signals changing when not expected.
You may search in forum messages about RMW effect and problems.
Also when microcontroller is running faster, with instruction frequency higher than 1 MHz,
then problems become even more noticable.
Thus, modern PIC microcontrollers, PIC16F1xxx and PIC16F1xxxx, PIC12F1xxx, ...
have separate SFR memory addresses for LATx register, and for PORTx register.
Write to LATx register or write to PORTx register actually go into the same place, the register of Port LATches.
Reading is different:
Reading from LATx register will read the contents of LATch flip-flops.
Reading from PORTx register will read from digital Input circuits.
See PORT chapter in Datasheet , and Diagram of I/O Port Operation.