Vault 7: Projects

This publication series is about specific projects related to the Vault 7 main publication.

PIC24F Family Reference Manual
DS39715A-page 4-16 Advance Information © 2007 Microchip Technology Inc.
4.6.4.2 NVMKEY REGISTER
NVMKEY is a write-only register that is used to prevent accidental writes/erasures of Flash
memory. To start a program or erase sequence, the following steps must be taken in the exact
order shown:
1. Write 0x55 to NVMKEY.
2. Write 0xAA to NVMKEY.
3. Execute two NOP instructions.
After this sequence, a write will be allowed to the NVMCON register for one instruction cycle. In
most cases, the user will simply need to set the WR bit in the NVMCON register to start the
program or erase cycle. Interrupts should be disabled during the unlock sequence. The code
example below shows how the unlock sequence is performed:
Example 4-5: Performing the Unlock Sequence
Refer to Section 4.7 “Flash Programming Operations” for further programming examples.
; PUSH SR ; Disable interrupts, if enabled
MOV #0x00E0,W0
IOR SR
MOV #0x55,W0
MOV #0xAA,W0
MOV W0,NVMKEY
MOV W0,NVMKEY ; NOP not required
BSET NVMCON,#WR ; Start the program/erase cycle
NOP
NOP
POP SR ; Re-enable interrupts
Equivalent C Code
NVMKEY = 0x55;
NVMKEY = 0xAA;
NVMCONbits.WR=1;
Nop();
Nop();
Note: Save all the working registers prior to using them.

e-Highlighter

Click to send permalink to address bar, or right-click to copy permalink.

Un-highlight all Un-highlight selectionu Highlight selectionh