新聞中心

AVR EEPROM讀寫

作者: 時(shí)間:2016-11-11 來源:網(wǎng)絡(luò) 收藏
void Write_byte_eeprom(unsigned short address,unsigned char data)

{
while (EECR&(1<EEAR = address;
EEDR = data;
EECR |= (1<EECR |= (1<}

本文引用地址:http://m.butianyuan.cn/article/201611/316567.htm

unsigned char Read_byte_eeprom(unsigned short address)
{
while (EECR&(1<EEAR = address;
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();
}

}



關(guān)鍵詞: AVREEPROM讀

評論


技術(shù)專區(qū)

關(guān)閉