Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

difference between port and lat register in pic

Status
Not open for further replies.

salamnamste

Newbie level 3
Joined
Sep 10, 2010
Messages
4
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,310
difference between port and lat register in pic?
the data sheet says port is for reading input and lat is for output.
but when i program port register equal to 0xFF, the LEDs connected with the port getting glow. how it is happens.
 

from the PIC24FJ256GB110 data sheet
"Reads from the Output Latch register (LATx), read the latch. Writes to the latch, write the latch.
Reads from the port (PORTx), read the port pins, while writes to the port pins, write the latch."
You set the TRIS bits to determine if the pin in input (1) or output(0).
You may also need to set the appropriate bit in the AD1PCFG* (or similar) register so the pin is digital rather than analogue.
If all is correct, when you 0xFF the LEDs may still glow depending upon the way they are wired - what happends if you write 0?
 

Hi,

The use of PORT and LAT is a well misunderstood point - as can be seen in virtually everones code examples where they still use PORT - myself included !

Think if you slowly read this PDF a few times you will see the important difference between the two.
**broken link removed**

Some quotes from Microchip manuals -

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.
Any bit and its associated data and control registers that are not valid for a particular device will
be disabled. That means the corresponding LATx and TRISx registers, and the port pin, will read
as zeros.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top