PPS Lock

The PPS module provides an extra layer of protection to prevent inadvertent changes to the PPS selection registers. The PPSLOCKED bit is used in combination with specific code execution blocks to lock/unlock the PPS selection registers.

Important: The PPSLOCKED bit is clear by default (PPSLOCKED = 0), which allows the PPS selection registers to be modified without an unlock sequence.

PPS selection registers are locked when the PPSLOCKED bit is set (PPSLOCKED = 1). Setting the PPSLOCKED bit requires a specific lock sequence as shown in the examples below in both C and assembly languages.

PPS selection registers are unlocked when the PPSLOCKED bit is clear (PPSLOCKED = 0). Clearing the PPSLOCKED bit requires a specific unlock sequence as shown in the examples below in both C and assembly languages.

Important: All interrupts should be disabled before starting the lock/unlock sequence to ensure proper execution.

PPS Lock Sequence (Assembly language)


 ; suspend interrupts
    BCF      INTCON0,GIE
    BANKSEL  PPSLOCK        
 ; required sequence, next 5 instructions
    MOVLW    0x55
    MOVWF    PPSLOCK 
    MOVLW    0xAA
    MOVWF    PPSLOCK
 ; Set PPSLOCKED bit 
    BSF      PPSLOCK,PPSLOCKED
 ; restore interrupts
    BSF      INTCON0,GIE

PPS Lock Sequence (C language using in-line assembly)


asm(”BCF INTCON0,GIE”);
asm(”BANKSEL PPSLOCK”);
asm(”MOVLW 0x55”);
asm(”MOVWF PPSLOCK”);
asm(”MOVLW 0xAA”);
asm(”MOVWF PPSLOCK”);
asm(”BSF PPSLOCK,PPSLOCKED”);
asm(”BSF INTCON0,GIE”);

PPS Unlock Sequence (Assembly language)


 ; suspend interrupts
    BCF      INTCON0,GIE
    BANKSEL  PPSLOCK
 ; required sequence, next 5 instructions
    MOVLW    0x55
    MOVWF    PPSLOCK 
    MOVLW    0xAA
    MOVWF    PPSLOCK
 ; Clear PPSLOCKED bit 
    BCF      PPSLOCK,PPSLOCKED
 ; restore interrupts
    BSF      INTCON0,GIE

PPS Unlock Sequence (C language using in-line assembly)


asm(”BCF INTCON0,GIE”);
asm(”BANKSEL PPSLOCK”);
asm(”MOVLW 0x55”);
asm(”MOVWF PPSLOCK”);
asm(”MOVLW 0xAA”);
asm(”MOVWF PPSLOCK”);
asm(”BCF PPSLOCK,PPSLOCKED”);
asm(”BSF INTCON0,GIE”);