AVR EEPROM讀寫
{
while (EECR&(1<
EEDR = data;
EECR |= (1<
unsigned char Read_byte_eeprom(unsigned short address)
{
while (EECR&(1<
EECR |= (1<
return EEDR;
}
void Refresh_eeprom(void)
{
unsigned char i = 0;
unsigned char check = 0;
unsigned char *p = (unsigned char *)&ram;
asm("cli");
ram.start = 0x55;
for (; i<(sizeof(ram)-1); i++)
{
Write_byte_eeprom(i,*(p+i));
check += *(p+i);
}
Write_byte_eeprom(i,check);
asm("sei");
}
void Read_eeprom(void)
{
unsigned char i = 0;
unsigned char check = 0;
unsigned char *p = (unsigned char *)&ram;
for (; i<(sizeof(ram)-1); i++)
{
*(p+i) = Read_byte_eeprom(i);
check += *(p+i);
}
*(p+i) = Read_byte_eeprom(i);
//取值合理性判斷
if ((*(p+i) != check) || (*p != 0x55))
{
Parameter_reset();
}
}
評論