18.5 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.
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.
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)
INTCON0bits.GIE = 0; //Suspend interrupts PPSLOCK = 0x55; //Required sequence PPSLOCK = 0xAA; //Required sequence PPSLOCKbits.PPSLOCKED = 1; //Set PPSLOCKED bit INTCON0bits.GIE = 1; //Restore interrupts
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)
INTCON0bits.GIE = 0; //Suspend interrupts PPSLOCK = 0x55; //Required sequence PPSLOCK = 0xAA; //Required sequence PPSLOCKbits.PPSLOCKED = 0; //Clear PPSLOCKED bit INTCON0bits.GIE = 1; //Restore interrupts