Store data in built-in Flash of PIC at runtime using C code

cflashmicrocontrollerprogramming

I am designing PIC16F877a based project that counts the number of people in a room and turn ON the relays in accordance with that number like if 5 persons in a room then One relay would be ON. I want user of the device to set the number according to their need therefore I want to store some integers variables (value defined by user) in a Flash memory on uC at runtime using C code. I have searched on Google but did not find any suitable answer.

Best Answer

With the processor you are using this should be as simple as eeprom_write(unsigned int address,unsigned char data), in which you can find the address of the eeprom/flash in the datasheets. Some processors don't seem to support this command though. If you look in the header file of the uC as well as the compiler header (eg. pic18.h) you can see whether certain commands have been commented out due to no definition being previously defined. If no definition, you will have to do it bit-wise and make sure that you do not cross with any vital program memory during run time.