用单片机内部的FLASH来仿真EEPROM,这个可以省一个EEPROM芯片,毕竟现在以挣钱干饭为主。
在Modustoolbox中选择新建工程,然后选择-062S2那个板子,选择建立Modustoolbox APP工程:
选择:EEPROM
建立工程后,直接去掉cycfg_system.c去掉一个define://#define CY_CFG_SYSCLK_WCO_ENABLED 1
然后编译运行:
可以看到,我每次重启后,数量都加一。这就是说仿EEPROM成功了。
而这段程序可以在Modustoolbox环境中看到:
/* The EEPROM content is valid. Increment Counter by 1. */
eeprom_read_array[RESET_COUNT_LOCATION+1]++;
/* Counter is in ASCII, so handle overflow. */
if(eeprom_read_array[RESET_COUNT_LOCATION+1] > ASCII_NINE)
{
/* Set lower digit to zero. */
eeprom_read_array[RESET_COUNT_LOCATION+1] = ASCII_ZERO;
/* Increment upper digit. */
eeprom_read_array[RESET_COUNT_LOCATION]++;
/* only increment to 99. */
if(eeprom_read_array[RESET_COUNT_LOCATION] > ASCII_NINE)
{
eeprom_read_array[RESET_COUNT_LOCATION] = ASCII_NINE;
eeprom_read_array[RESET_COUNT_LOCATION+1] = ASCII_NINE;
}
}
/* Only update the two count values in the EEPROM. */
eeprom_return_value = Cy_Em_EEPROM_Write(RESET_COUNT_LOCATION,
&eeprom_read_array[RESET_COUNT_LOCATION],
RESET_COUNT_SIZE,
&Em_EEPROM_context);
handle_error(eeprom_return_value, "Emulated EEPROM Write failed \r\n");