STORING VARIABLES IN FLASH PROMS 18F4455

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 4.
To post in this forum you must have a registered copy of Flowcode 4 or higher. To sign up for this forum topic please use the "Online Resources" link in the Flowcode Help Menu.

Moderator: Benj

Post Reply
PUTS_JO
Posts: 20
Joined: Wed Sep 01, 2010 8:11 am
Has thanked: 1 time

STORING VARIABLES IN FLASH PROMS 18F4455

Post by PUTS_JO »

BEST E BLOCK USERS

At the moment I am trying to store one variable in flash memory of the 18f4455. In the manual of 'pic microcontrollers know it all' i read some info of doing this . it is only possible by using a c program where you have to put in the '#include flash.pic16.lib ' together with some code as
flash_read (FCV_FLASHADDRESS+FCV_RETRIEVE); when calling an individual byte number...Does somebody know at the matrix site a good manual with all the c-commands that can be used in flowcode, because the help file does not support c commands with a short explanation;
or does somebody know a good starting example;inclusive the library setups and all..... :roll: :roll:
thanks in advance
puts johan belgium

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: STORING VARIABLES IN FLASH PROMS 18F4455

Post by Benj »

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.

PUTS_JO
Posts: 20
Joined: Wed Sep 01, 2010 8:11 am
Has thanked: 1 time

Re: STORING VARIABLES IN FLASH PROMS 18F4455

Post by PUTS_JO »

BEST BENJ

I have implemented the code in a c window but i get now an error that there is a syntax error ; i have declared new variables as DATA and ADDRESS but what about FCV_DATA and FCV_ADDRESS ? i am also new user for these topics ; i mean i have programmed for years in c and c++ but
in flowcode is new for me. I looked also in the forum to some programs but they have a main section. Do i have to have a main section or not because as I understoot the flowcode itself is one big C program... where the C code is just compiled as a subroutine or is this wrong???
how do i start from scratch starting a c routine in flowcode .....is there a small tutorial for it ???
thanks

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: STORING VARIABLES IN FLASH PROMS 18F4455

Post by Benj »

Hello,

Your main Flowchart window is essentially your C main routine.

Flowcode variables get renamed in C so the variable data in Flowcode would become FCV_DATA in C.

What syntax errors are you getting? Maybe attach your program to the forum and I will have a look at it.

Post Reply