Unlock Sequence

As an extra layer of protection against memory corruption, a specific code execution unlock sequence is required to initiate a write or erase operation. Both C and assembly examples are shown below. The C example uses in-line assembly to force the compiler to generate the proper sequence. All interrupts should be disabled before starting the unlock sequence to ensure proper execution.

Unlock sequence in C

    asm(”movlw 0x55”);
    asm(”movwf NVMLOCK”);
    asm(”movlw 0xAA”);
    asm(”movwf NVMLOCK”);
    asm(”bsf NVMCON0,GO”);

Unlock sequence in assembly

    movlw    0x55
    movwf    NVMLOCK
    movlw    0xAA
    movwf    NVMLOCK
    bsf      NVMCON0,GO