DIY编程器网

标题: AVR单片机读写EEPROM子程序 [打印本页]

作者: liyf    时间: 2012-1-27 19:43
标题: AVR单片机读写EEPROM子程序
  
         
    void EEPROM_write(unsigned int uiAddress, unsigned char ucData)
{
/* 等待上一次写操作结束 */
while(EECR & (1<<EEWE))
;
/* 设置地址和数据寄存器*/
EEAR = uiAddress;
EEDR = ucData;
/* 置位EEMWE */
EECR |= (1<<EEMWE);
/* 置位EEWE 以启动写操作*/
EECR |= (1<<EEWE);
}
unsigned char EEPROM_read(unsigned int uiAddress)
{
/* 等待上一次写操作结束 */
while(EECR & (1<<EEWE))
;
/* 设置地址寄存器*/
EEAR = uiAddress;
/* 设置EERE 以启动读操作*/
EECR |= (1<<EERE);
/* 自数据寄存器返回数据 */
return EEDR;
}
void EEPROM_read_block(unsigned char *store_point,
unsigned int _uiAddress,unsigned char n)
{
unsigned char i;
//unsigned int x1;
//unsigned char x2;
for(i=0;i<n;i++)
{
//x2=EEPROM_read(_uiAddress);
//_uiAddress++;
//x1=EEPROM_read(_uiAddress);
//x1<<8;
//x1=x1+x2;
//* store_point=x1;
* store_point=EEPROM_read(_uiAddress);
store_point++;
_uiAddress++;
}
}  


      
作者: zyh555    时间: 2013-1-30 12:22
很不错,谢谢楼主分享!




欢迎光临 DIY编程器网 (http://diybcq.com/) Powered by Discuz! X3.2