I have a program in C and inside the routine "Void Main" I need to write and then read a value in ROM, then I update this value to save again in ROM. This value can not be lost in case of power failure. Resident routines did not work. Does anyone have any routine about this? Thank you.
Have you looked at this application note? It is mostly concerned with using the ROM monitor resident routines. But, the information has some application to requirements if you are to be writing your own code. As you may know, one cannot be executing code out of the flash program space at the same time as any erase or program operation is ongoing to the flash program address space. So, you must write a routine to perform the erase operation or the program operation in your code, copy that routine to unused RAM space, and jump execution to that routine. After it has finished you can go back to your flash code. You must take care to not erase your own code from flash!
http://www.nxp.com/assets/documents/data/en/application-notes/AN1831.pdf