Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

PIC PORTA vs LATA

Status
Not open for further replies.

Oznog

Active Member
I want to be sure I know the difference between PORTx and LATx in the PIC. My C compiler seems to allow them interchangably.

I saw in the PIC18 data sheet that LATx was memory mapped and thus could be used with a Read/Modify/Write option, whereas PORTx only allows a read or write of the whole port and any "Modify" would involve storing the value elsewhere, which takes multiple cycles and thus involves the risk of losing values from pins used as inputs.

Is that correct? Is that the only difference? I think the compiler is selecting the proper assembly instruction for the operation and the PORTx/LATx aren't different, but I'd like to check.
 
I use the HI-TECH C compliler and you have to explicity state which command you want to use. If you use PORTx for read-modify-write you will get erronious results.
 
This prob with PORTx only corrupts the stored output latch value for a pin declared as an input, and only shows up when the pin is changed to an output before reassigning the output latch?

So, is there ever any reason to use PORTx over LATx anymore, or is it just a matter of backwards compatability?
 
I saw the problem using PORTx when assigning the output value using bit wise assignments.

For Example:

PORTA |= 0x04;
PORTA |= 0x01;

This will cause oscillations of the output values.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top