您的位置 首页 数字

AVR EEPROM读写

voidWrite_byte_eeprom(unsignedshortaddress,unsignedchardata){while(EECR(1EEWE));//等待EEWE变为0EEAR=addr

void Write_byte_eeprom(unsigned short address,unsigned char data)

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

unsigned char Read_byte_eeprom(unsigned short address)
{
while (EECR&(1<EEAR = address;
EECR |= (1<}

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();
}

}

声明:本文内容来自网络转载或用户投稿,文章版权归原作者和原出处所有。文中观点,不代表本站立场。若有侵权请联系本站删除(kf@86ic.com)https://www.86ic.net/zhishi/shuzi/274301.html

为您推荐

联系我们

联系我们

在线咨询: QQ交谈

邮箱: kf@86ic.com

关注微信
微信扫一扫关注我们

微信扫一扫关注我们

返回顶部