unsigned char min_change0=0, //要保存的变量值第一组,每一次改变都会保存 unsigned char min_change_backup0=0; //该变量为中间变量,用于与min_change做对比,下同 unsigned char min_change1=0, //要保存的变量值第二组,每一次改变都会保存 unsigned char min_change_backup1=0; unsigned char min_change2=0, //要保存的变量值第三组,每一次改变都会保存 unsigned char min_change_backup2=0; void EEPROM_Write(timeset*, unsigned char, unsigned char) ; //数据保存并写入EEPROM EEPROM_write(unsigned char, unsigned char, ); //内部EEPROM写入函数 typedef struct EEPROM_Save { unsigned char* min_set; unsigned char* min_set_backup; } timeset; timeset EEPROM_SAVE[3] ={ //定义并初始化一个结构体数组,数组元素是指针,数组元素为三组需要保存的数据 {&min_change0, &min_change_backup0}, {&min_change1, &min_change_backup1}, {&min_change2, &min_change_backup2} }; int main(void) { while(1) { for(int j=0; j <3; j++) { EEPROM_Write(EEPROM_SAVE, j, (j+1)) ; } } } void EEPROM_Write(timeset* table, unsigned char i, unsigned char addr) { if (*(table[i].min_set) != *(table[i].min_set_backup)) //如果min_change和min_change_backup不相等,则开始保存 { *(table[i].min_set_backup) = *(table[i].min_set) ; //保存数据 EEPROM_write(addr, *(table[i].min_set_backup)); //写入EEPROM } }
标签:min,写入,unsigned,C语言,char,保存,change,EEPROM,eeprom From: https://www.cnblogs.com/mokongking/p/17275415.html