16.4 PPS Lock

The PPS includes a mode in which all input and output selections can be locked to prevent inadvertent changes. PPS selections are locked by setting the PPSLOCKED bit of the PPSLOCK register. Setting and clearing this bit requires a special sequence as an extra precaution against inadvertent changes. Examples of setting and clearing the PPSLOCKED bit are shown in the following examples.

PPS Lock Sequence

 ; suspend interrupts
    BCF      INTCON,GIE
    BANKSEL  PPSLOCK ; set bank
 ; required sequence, next 5 instructions
    MOVLW    0x55
    MOVWF    PPSLOCK 
    MOVLW    0xAA
    MOVWF    PPSLOCK
 ; Set PPSLOCKED bit to disable writes or
    BSF      PPSLOCK,PPSLOCKED
 ; restore interrupts
    BSF      INTCON,GIE

PPS Unlock Sequence

 ; suspend interrupts
    BCF      INTCON,GIE
    BANKSEL  PPSLOCK ; set bank
 ; required sequence, next 5 instructions
    MOVLW    0x55
    MOVWF    PPSLOCK
    MOVLW    0xAA
    MOVWF    PPSLOCK
 ; Clear PPSLOCKED bit to enable writes
    BCF      PPSLOCK,PPSLOCKED
 ; restore interrupts
    BSF      INTCON,GIE
Note:
  1. The PPSLOCK bit can only be set or cleared after the unlock sequence shown above.
  2. If PPS1WAY = 1, the PPSLOCK bit cannot be cleared after it has been set.