В чём разница между LATA и PORTA ?
05.02.2025

With the usage of PORTx for writing to an output you may easily run into read-modify-write-problems. For example, this part of code will only set PORTA,3 (PORTA was clear before), if you have some capacitive load on your pins (for example, 1 uF):

    BSF PORTA,0
    BSF PORTA,1  ;This instruction read the present state of PORTA, and because of the capacitor on PORTA,0 the input-level on 
                     ;PORTA,0 is still low, so only '00000010' will be written back to the port
    BSF PORTA,2  ;This instruction read the present state of PORTA, and because of the capacitor on PORTA,1 the input-level on 
                     ;PORTA,1 is still low, so only '00000100' will be written back to the port
    BSF PORTA,3  ;This instruction read the present state of PORTA, and because of the capacitor on PORTA,2 the input-level on 
                     ;PORTA,2 is still low, so only '00001000' will be written back to the port

Using the LATx-register you can avoid this:

    BSF LATA,0
    BSF LATA,1
    BSF LATA,2
    BSF LATA,3

Here all four pins on Port A (0-3) are set.

 

оригинал обсуждения