CCS News

Add Non-Volatile Storage to Any PIC® MCU with the virtual EEPROM driver

Tuesday 07 June, 2016

Looking to store settings or data in your embedded project, but you are using a PIC® MCU without an internal EEPROM and your design doesn't have an external EEPROM? The virtual EEPROM driver included in the CCS C Compiler adds the ability to use the PIC® MCU's re-programmable flash memory as data storage. This driver also performs write balancing, which allows the developer to write to a specific location several times without fear of wearing out the endurance of the flash memory. The virtual EEPROM driver recently was updated to add support for PIC16 and to optimize the memory usage when used on 8-bit PIC® MCUs (PIC16, PIC18, etc).

To add this library into your project, simply #include the file virtual_eeprom.c. The function init_virtual_eeprom() needs to be called to initialize access to the virtual EEPROM. write_virtual_eeprom() can be used to write a value to a location, and read_virtual_eeprom() can be used to read the value at a specified location. The last two erase pages of the PIC's re-programmable flash are used as storage for the virtual EEPROM system.

Here is an example of usage:

#include <virtual_eeprom.c>

void test_virtual_eeprom(void)
{
init_virtual_eeprom();
write_virtual_eeprom(0, 55);
write_virtual_eeprom(1, 65);
write_virtual_eeprom(2, 75);
printf("%urn", read_virtual_eeprom(0)); //should say '55'
printf("%urn", read_virtual_eeprom(1)); //should say '65'
printf("%urn", read_virtual_eeprom(2)); //should say '75'
}

Like us on Facebook. Follow us on Twitter.

About CCS:

CCS is a leading worldwide supplier of embedded software development tools that enable companies to develop premium products based on Microchip PIC® MCU and dsPIC® DSC devices. Complete proven tool chains from CCS include a code optimizing C compiler, application specific hardware platforms and software development kits. CCS' products accelerate development of energy saving industrial automation, wireless and wired communication, automotive, medical device and consumer product applications. Established in 1992, CCS is a Microchip Premier 3rd Party Partner. For more information, please visit http://www.ccsinfo.com.

PIC® MCU, MPLAB® IDE, MPLAB® ICD2, MPLAB® ICD3 and dsPIC® are registered trademarks of Microchip Technology Inc. in the U.S. and other countries.