# Dspic33fj12mc202: FLASH Self Write Question

**URL:** <https://forum.digikey.com/t/dspic33fj12mc202-flash-self-write-question/15822>\
**Category:** Integrated Circuits (ICs)\
**Tags:** microchip-technology, embedded\
**Created:** [August 6, 2021, 4:49pm UTC](https://forum.digikey.com/t/dspic33fj12mc202-flash-self-write-question/15822 "2021-08-06T16:49:53Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![aaneesh444](https://avatars.discourse-cdn.com/v4/letter/a/b4bc9f/32.png) [@aaneesh444](https://forum.digikey.com/u/aaneesh444)\
**Post date:** [August 6, 2021, 4:49pm UTC](https://forum.digikey.com/t/dspic33fj12mc202-flash-self-write-question/15822/1 "2021-08-06T16:49:53Z")

</div>

From: [FLASH Self Write Microchip dsPIC33F, PIC24H](https://forum.digikey.com/t/flash-self-write-microchip-dspic33f-pic24h/13278)

Hi sir, I tested the file…its working…I want to change parameter individually…when I write parameter[1]  
All parameter is changing…but parameter[1] value is same what I have written …but other value is changing…can you help me…

---

<div class="post-metadata">

**Author:** ![RobertCNelson](https://sea2.discourse-cdn.com/digikey/user_avatar/forum.digikey.com/robertcnelson/32/12_2.png) [@RobertCNelson](https://forum.digikey.com/u/RobertCNelson)\
**Post date:** [August 6, 2021, 7:55pm UTC](https://forum.digikey.com/t/dspic33fj12mc202-flash-self-write-question/15822/2 "2021-08-06T19:55:19Z")

</div>

Hi @aaneesh444 which mcu are you using? Can you share what you changed? and what you want to do…

Please use code blocks (```) pre and post text:

```auto
code block

```

Regards,

---

<div class="post-metadata">

**Author:** ![RobertCNelson](https://sea2.discourse-cdn.com/digikey/user_avatar/forum.digikey.com/robertcnelson/32/12_2.png) [@RobertCNelson](https://forum.digikey.com/u/RobertCNelson)\
**Post date:** [August 9, 2021, 12:59am UTC](https://forum.digikey.com/t/dspic33fj12mc202-flash-self-write-question/15822/7 "2021-08-09T00:59:34Z")

</div>

> [@aaneesh444](#):
>
> But not able to do more array…more than 8 array…not locating program memory…can I change address value in that…may be my memory not enough…

When looking at Kevin’s posted code: (programParameters), it is specifically tuned for 3 integers, did you extend this code when you changed it to an array of 8?

```auto
/ ********************************************************************************
 * programParameters()
 *
 * Prototype: int programParameters(unsigned int, unsigned int, unsigned int)
 * Passed arguments: unsigned int param1, unsigned int param2, unsigned int param3
 * Return value: none
 * Dependencies: INTERRUPTS MUST be DISABLED prior to calling this routine.
 *
 * Description: Erase block of NVM and write data to FLASH memory
 ******************************************************************************** /
void programParameters(unsigned int param1, unsigned int param2, unsigned int param3)
{
    unsigned int tbloffset;
 
    //Erase one page of FLASH memory
    NVMCON = 0x4042; // Setup NVMCON for Block Erase operation (512 instructions)
    TBLPAG = __builtin_tblpage(&iParameters[0]); // Load upper FLASH address
    tbloffset = __builtin_tbloffset(&iParameters[0]); // Offset within page
    __builtin_tblwtl(tbloffset, 0xFFFF); // Dummy write to select the page
    FLASHWrite(); // low level erase/write command sequence
 
    // write single word, param1, to FLASH
    // In this case the Page hasn't changed so don't have to load the table
    // page register again.
    tbloffset = __builtin_tbloffset(&iParameters[0]); // offset within page
    __builtin_tblwtl(tbloffset, param1); // load the write buffer
    NVMCON = 0x4003; // Setup NVMCON for Single Word Write operation
    FLASHWrite(); // low level erase/write command sequence
 
    // write single word, param2, to FLASH
    tbloffset = __builtin_tbloffset(&iParameters[1]); // offset within page
    __builtin_tblwtl(tbloffset, param2); // load the write buffer
    NVMCON = 0x4003; // Setup NVMCON for Single Word Write operation
    FLASHWrite(); // low level erase/write command sequence
 
    // write single word, param3, to FLASH
    tbloffset = __builtin_tbloffset(&iParameters[2]); // offset within page
    __builtin_tblwtl(tbloffset, param3); // load the write buffer
    NVMCON = 0x4003; // Setup NVMCON for Single Word Write operation
    FLASHWrite(); // low level erase/write command sequence
 
    return;
}

```
