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

; Disable interrupts:
   BCF    INTCON,GIE
; Bank to PPSLOCK register
   BANKSEL PPSLOCK
   MOVLW   55h
; Required sequence, next 4 instructions
   MOVWF   PPSLOCK
   MOVLW   AAh
   MOVWF   PPSLOCK
; Set PPSLOCKED bit to disable writes
; Only a BSF instruction will work
   BSF     PPSLOCK,PPSLOCKED
; Enable Interrupts
   BSF     INTCON,GIE

PPS Unlock Sequence

; Disable interrupts:
   BCF     INTCON,GIE
; Bank to PPSLOCK register
   BANKSEL PPSLOCK
   MOVLW   55h
; Required sequence, next 4 instructions
   MOVWF   PPSLOCK
   MOVLW   AAh
   MOVWF   PPSLOCK
; Clear PPSLOCKED bit to enable writes
; Only a BCF instruction will work
   BCF     PPSLOCK,PPSLOCKED
; Enable Interrupts
   BSF     INTCON,GIE