10.07.2015 Views

pic24fj128ga010 family - Microchip

pic24fj128ga010 family - Microchip

pic24fj128ga010 family - Microchip

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

PIC24FJ128GA010 FAMILY4.6.2 PROGRAMMING A SINGLE WORDOF FLASH PROGRAM MEMORYIf a Flash location has been erased, it can be programmedusing table write instructions to write aninstruction word (24-bit) into the write latch. TheTBLPAG register is loaded with the 8 Most SignificantBytes of the Flash address. The TBLWTL and TBLWTHinstructions write the desired data into the write latchesand specify the lower 16 bits of the program memoryaddress to write to. To configure the NVMCON registerfor a word write, set the NVMOP bits (NVMCON)to ‘0011’. The write is performed by executing theunlock sequence and setting the WR bit.EXAMPLE 4-4:PROGRAMMING A SINGLE WORD OF FLASH PROGRAM MEMORY; Setup a pointer to data Program MemoryMOV #tblpage(PROG_ADDR), W0 ;MOV W0, TBLPAG ;Initialize PM Page Boundary SFRMOV #tbloffset(PROG_ADDR), W0 ;Initialize a register with program memory addressMOV #LOW_WORD_N, W2 ;MOV #HIGH_BYTE_N, W3 ;TBLWTL W2, [W0] ; Write PM low word into program latchTBLWTH W3, [W0++] ; Write PM high byte into program latch; Setup NVMCON for programming one word to data Program MemoryMOV #0x4003, W0 ;MOV W0, NVMCON ; Set NVMOP bits to 0011DISI #5 ; Disable interrupts while the KEY sequence iswrittenMOV #0x55, W0 ; Write the key sequenceMOV W0, NVMKEYMOV #0xAA, W0MOV W0, NVMKEYBSET NVMCON, #WR ; Start the write cycleDS39747E-page 52© 2009 <strong>Microchip</strong> Technology Inc.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!