微波EDA网,见证研发工程师的成长!
首页 > 硬件设计 > 嵌入式设计 > AVR EEPROM读写

AVR EEPROM读写

时间:11-11 来源:互联网 点击:
void Write_byte_eeprom(unsigned short address,unsigned char data)

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

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

}

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top