10.07.2015 Views

pic24fj128ga010 family - Microchip

pic24fj128ga010 family - Microchip

pic24fj128ga010 family - Microchip

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

PIC24FJ128GA010 FAMILY4.6.1 PROGRAMMING ALGORITHM FORFLASH PROGRAM MEMORYThe user can program one row of program Flash memoryat a time. To do this, it is necessary to erase the 8-rowerase block containing the desired row. The generalprocess is:1. Read eight rows of program memory(512 instructions) and store in data RAM.2. Update the program data in RAM with thedesired new data.3. Erase the block (see Example 4-1):a) Set the NVMOP bits (NVMCON) to‘0010’ to configure for block erase. Set theERASE (NVMCON) and WREN(NVMCON) bits.b) Write the starting address of the block to beerased into the TBLPAG and W registers.c) Write 55h to NVMKEY.d) Write AAh to NVMKEY.e) Set the WR bit (NVMCON). The erasecycle begins and the CPU stalls for the durationof the erase cycle. When the erase isdone, the WR bit is cleared automatically.4. Write the first 64 instructions from data RAM intothe program memory buffers (see Example 4-2).5. Write the program block to Flash memory:a) Set the NVMOP bits to ‘0001’ to configurefor row programming. Clear the ERASE bitand set the WREN bit.b) Write 55h to NVMKEY.c) Write AAh to NVMKEY.d) Set the WR bit. The programming cyclebegins and the CPU stalls for the duration ofthe write cycle. When the write to Flashmemory is done, the WR bit is clearedautomatically.6. Repeat steps 4 and 5, using the next available64 instructions from the block in data RAM byincrementing the value in TBLPAG, until all512 instructions are written back to Flashmemory.For protection against accidental operations, the writeinitiate sequence for NVMKEY must be used to allowany erase or program operation to proceed. After theprogramming command has been executed, the usermust wait for the programming time until programmingis complete. The two instructions following the start ofthe programming sequence should be NOPs, as shownin Example 4-3.EXAMPLE 4-1:ERASING A PROGRAM MEMORY BLOCK; Set up NVMCON for block erase operationMOV #0x4042, W0 ;MOV W0, NVMCON ; Initialize NVMCON; Init pointer to row to be ERASEDMOV #tblpage(PROG_ADDR), W0 ;MOV W0, TBLPAG ; Initialize PM Page Boundary SFRMOV #tbloffset(PROG_ADDR), W0 ; Initialize in-page EA[15:0] pointerTBLWTL W0, [W0] ; Set base address of erase blockDISI #5 ; Block all interrupts with priority

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

Saved successfully!

Ooh no, something went wrong!