10.10 OSCCON Unlock Sequence

The OSCCON register is protected against unintended writes through a lock mechanism. The upper and lower bytes of OSCCON have their own unlock sequence, and both must be used when writing to both bytes of the register.

Before OSCCON can be written to, the following unlock sequence must be used:

  1. Execute the unlock sequence for the OSCCON high byte. In two back-to-back instructions:
    • Write 0x78 to OSCCON[15:8]
    • Write 0x9A to OSCCON[15:8]
  2. In the instruction immediately following the unlock sequence, the OSCCON[15:8] bits can be modified.
  3. Execute the unlock sequence for the OSCCON low byte. In two back-to-back instructions:
    • Write 0x46 to OSCCON[7:0]
    • Write 0x57 to OSCCON[7:0]
  4. In the instruction immediately following the unlock sequence, the OSCCON[7:0] bits can be modified.
Note: MPLAB® XC16 provides a built-in C language function, including the unlocking sequence to modify high and low bytes in the OSCCON register:
 __builtin_write_OSCCONH(value)


__builtin_write_OSCCONL(value)