English
Language : 

PIC24F04KA201 Datasheet, PDF (51/224 Pages) Microchip Technology – 14/20-Pin General Purpose, 16-Bit Flash Microcontrollers with nanoWatt XLP™ Technology
PIC24F04KA201 FAMILY
EXAMPLE 5-5: INITIATING A PROGRAMMING SEQUENCE – ASSEMBLY LANGUAGE CODE
DISI
MOV
MOV
MOV
MOV
BSET
NOP
NOP
BTSC
BRA
#5
#0x55, W0
W0, NVMKEY
#0xAA, W1
W1, NVMKEY
NVMCON, #WR
NVMCON, #15
$-2
; Block all interrupts
for next 5 instructions
; Write the 55 key
;
; Write the AA key
; Start the erase sequence
; 2 NOPs required after setting WR
;
; Wait for the sequence to be completed
;
EXAMPLE 5-6: INITIATING A PROGRAMMING SEQUENCE – ‘C’ LANGUAGE CODE
// C example using MPLAB C30
asm("DISI #5");
// Block all interrupts for next 5 instructions
__builtin_write_NVM();
// Perform unlock sequence and set WR
EXAMPLE 5-7: PROGRAMMING A SINGLE WORD OF FLASH PROGRAM MEMORY
; Setup a pointer to data Program Memory
MOV
#tblpage(PROG_ADDR), W0
;
MOV
W0, TBLPAG
;Initialize PM Page Boundary SFR
MOV
#tbloffset(PROG_ADDR), W0
;Initialize a register with program memory address
MOV
#LOW_WORD_N, W2
;
MOV
#HIGH_BYTE_N, W3
;
TBLWTL W2, [W0]
; Write PM low word into program latch
TBLWTH W3, [W0++]
; Write PM high byte into program latch
; Setup NVMCON for programming one word to data Program Memory
MOV
#0x4003, W0
;
MOV
W0, NVMCON
; Set NVMOP bits to 0011
DISI #5
; Disable interrupts while the KEY sequence is written
MOV
#0x55, W0
; Write the key sequence
MOV
W0, NVMKEY
MOV
#0xAA, W0
MOV
W0, NVMKEY
BSET NVMCON, #WR
; Start the write cycle
© 2009 Microchip Technology Inc.
Preliminary
DS39937B-page 49