dsPIC33E/os_dsPIC33E_APIsB.c
// Function to erase a page of data in program memory.
// Author       : Fabian Kung
// Last Modified: 28 Nov 2018
// Arguments    : unTablePage - Page number (for NVMADRU register) of the address
//                to the first word in program memory to read.
//                unTableOffset - Offset address to the first word in program
//                memory to read.
// Example of usage:
// Assuming progData[] contains an array of integer data store in the program
// memory, we thus need to provide the page and offset address of the first
// element of progData[0] to this function.  To do this we use the built-in
// function that comes with the C-compiler.  We also assume the address of progData[0]
// is already aligned to the page boundary.  If this is not the case, the nearest
// address smaller than &progData[0] will be used.
//
// ProgMemErasePage(__builtin_tblpage(progData),__builtin_tbloffset(progData));
//

Function to erase a page of data in program memory.
Author       : Fabian Kung
Last Modified: 28 Nov 2018
Arguments    : unTablePage - Page number (for NVMADRU register) of the address
to the first word in program memory to read.
unTableOffset - Offset address to the first word in program
memory to read.
Example of usage:
Assuming progData[] contains an array of integer data store in the program
memory, we thus need to provide the page and offset address of the first
element of progData[0] to this function.  To do this we use the built-in
function that comes with the C-compiler.  We also assume the address of progData[0]
is already aligned to the page boundary.  If this is not the case, the nearest
address smaller than &progData[0] will be used.


Function to erase a page of data in program memory . Author : Fabian Kung Last Modified : 28 Nov 2018 Arguments : unTablePage - Page number ( for NVMADRU register ) of the address to the first word in program memory to read . unTableOffset - Offset address to the first word in program memory to read . Example of usage : Assuming progData [] contains an array of integer data store in the program memory we thus need to provide the page and offset address of the first element of progData [ 0 ] to this function . To do this we use the built - in function that comes with the C - compiler . We also assume the address of progData [ 0 ] is already aligned to the page boundary . If this is not the case the nearest address smaller than &progData [ 0 ] will be used .
void ProgMemErasePage(unsigned int unTablePage, unsigned int unTableOffset)
{
    NVMADRU = unTablePage;
    NVMADR = (unTableOffset & 0xF800); 
    NVMCON = 0x4003;            
    __builtin_disi(6);          
    __builtin_write_NVM();      
}
void ProgMemErasePage ( unsigned int unTablePage , unsigned int unTableOffset ) { NVMADRU = unTablePage ; NVMADR = ( unTableOffset & 0xF800 ) ; NVMCON = 0x4003 ; __builtin_disi ( 6 ) ; __builtin_write_NVM ( ) ; }
Function to erase a page of data in program memory.
Function to erase a page of data in program memory .
// For page size of 1024 24-bits words 
 // or 2x1024 16-bits words in the program memory.
 // 2x1024 - 1 = 2047 or 0x7FF.  Thus the the lower
 // 11-bits of the starting address is always 0.  
 // If the lower 11-bits of offset is not 0, it 
 // means the address of progData starts after the
 // page boundary, so we adjust it to start at the 
 // page boundary. 
 // Set WREN and Page Erase in NVMCON.
 // Disable interrupts.
 // Initiate write process.
