Hello,
You can use the following C functions. Put them into the lower window of the supplementary code window.
Code: Select all
char read_register(unsigned int address)
{
char RetVal;
volatile char* register_ptr = (char*)address;
RetVal = *register_ptr;
return RetVal;
}
void write_register(unsigned int address, char data)
{
volatile char* register_ptr = (char*)address;
*register_ptr = data;
}
Then in the upper window of the suplementary code place the function prototypes.
Code: Select all
char read_register(unsigned int address);
void write_register(unsigned int address, char data);
Once you have done this then the functions can be called from your program by using the following calls in a C code icon.
Code: Select all
write_register (FCV_ADDRESS, FCV_DATA);
or
Code: Select all
FCV_DATA = read_register(FCV_ADDRESS);
Using Flowcode variables data and address.
Please note you do not need to add the supplementary code prototypes and functions if you have the ICD enabled as the functions exist as part of the ICD code structure that gets automatically included.
Also note that flash memory can only be overwritten around 10,000 times before it burns out so if you are storing a value every second or even every minute then the device will not run for long before it cannot overwrite the location any more. 10,000 seconds is around 2.7 hours and 10,000 minutes is just shy of 1 week.
Also your main program is stored in Flash and also all the peripheral registers so make sure you are overwriting empty space otherwise you may inadvertantly start corrupting your program or your peripherals.