Many of the devices we commonly use have the ability to remember the situation in which they were before shutdown so as to repropose it when turned on, or have the ability to remember particular user settings so you do not have to enter them every time the device is started.

In PIC microcontroller, a cheep way of achieving these functions is to use a particular permanent memory called EEPROM. This area is used for long-term data storage, it is not accessible like other memory areas because it is not mapped like other memory areas.

To access the EEPROM it would be necessary to use the "Special Function Registers" if the MCC tool did not exists, which can prepare for us the functions necessary to write and read the contents of the memory without getting into the delicate setting of the SFR.

We create a new project as shown in the post "PIC microcontroller from scratch" and connect it to a serial as in the post "A couple words via RS232" at this point you just have to start MCC, select in the column "Device Resources" the entry "Memory" (by clicking on it twice) and enabling the function as shown in the figure.

Schermata 2017 12 26 alle 15.20.25 

Pressing the "Generate" button you create two new files: memory.h and memory.c. Inside the files there are several functions including those for reading and writing flash memory; the functions we are interested in are DATAEE_ReadByte and DATAEE_WriteByte which refer to the EEPROM memory. Their use is particularly simple, keep in mind that it is necessary to act one byte at a time. This is an example:


Here is the result on the RS232 terminal of the complete sample program downloadable from github download project :