User manual

372
mikoC PRO for dsPIC
MikroElektronika
Library Example
In this example written for dsPIC30F4013, various read/write tecniques to/from the on-chip FLASH memory are shown.
Flash memory is mapped to address space 3:2, meaning every 3 consecutive bytes of Flash have 2 consecutive
address locations available.
That is why mikroE's library allows data to be written to Flash in two ways: 'regular' and 'compact'. In 'regular' mode,
which is used for variables that are size of 2 bytes and more, the 3rd (un-addressable) byte remains unused.
In 'compact' mode, which can be used for 1 byte-sized variables/arrays, all bytes of ash are being used.
Copy Code To Clipboard
unsigned int iArr[8] = {‘m’, ‘i’, ‘k’, ‘r’, ‘o’, ‘E’, ‘l’, ‘e’};
char cArr[] = “mikroElektronika Flash example”;
char cArr2[40];
void * pv1;
unsigned bb;
void main() {
unsigned i;
pv1 = cArr;
/*
This is what FLASH_Write_Compact() does ‘beneath the hood’
*
FLASH_Write_Init(0x006000, pv1);
FLASH_Write_Loadlatch4_Compact();
FLASH_Write_Loadlatch4_Compact();
FLASH_Write_Loadlatch4_Compact();
FLASH_Write_DoWrite();
*/
//--- erase the block rst
FLASH_Erase32(0x006000);
//--- write compact format to ash
FLASH_Write_Compact(0x006000, pv1, 36);
//--- read compact format
pv1 = cArr2;
FLASH_Read4_Compact(0x006000, pv1);
pv1 += 12;
FLASH_Read4_Compact(0x006008, pv1);
pv1 += 12;
FLASH_Read4_Compact(0x006010, pv1);
pv1 += 12;
*pv1 = 0; //termination
//--- show what has been written
i = 0;