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 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.