avr eeprom保护方法
编译环境:WinAVR-20060421
基本思路:每份写到EEPRM的数据,都做三个备份,每个备份的数据都做CRC16校验,只要系统运行中出错,错误地修改了EEPROM数据,
EEPROMSave.h
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
EEPROMSave.c
unsigned
{
unsigned
data
eeprom_busy_wait();
data
return
}
uint16_t
{
uint16_t
data
eeprom_busy_wait();
data
return
}
void
{
eeprom_busy_wait();
eeprom_write_byte(address,data);
}
void
{
eeprom_busy_wait();
eeprom_write_word(address,data);
}
void
{
unsigned
for
{
EepromWriteByte((unsigned
buff++;
}
}
unsigned
{
unsigned
unsigned
crc
ref_crc
for
{
crc
for
{
if
{
crc
}
else
{
crc
}
}
pdata
}
ref_crc
ref_crc
pdata
ref_crc
if
{
return
}
else
{
return
}
}
unsigned
{
unsigned
unsigned
crc
for
{
crc
for
{
if
{
crc
}
else
{
crc
}
}
pdata
}
EepromWriteByte(pdata,(uint8_t)
pdata
EepromWriteByte(pdata,(uint8_t)
pdata
if
{
return
}
else
{
return
}
}
uint8_t
{
if