求助AVR EEPROM字符串读写
自己写了个程序,很多错误和警告,怎么解决.#include <avr/io.h>
void EEPROM_Write(unsigned int ucAddress,unsigned char ucData){
//等待上一次写结束
while (EECR & (1<<EEWE));
//设置地址寄存器
EEAR = ucAddress;
//设置数据寄存器
EEDR = ucData;
//使能EEPROM写操作
EECR |= (1<<EEMWE);
//开始EEPROM写操作
EECR |= (1<<EEWE);
}
unsigned char EEPROM_Read(unsigned int uiAddress){
//等待上一次写结束
while(EECR & (1<<EEWE));
//设置地址寄存器
EEAR = uiAddress;
//使能EEPROM读操作
EECR = (1<<EERE);
//返回EEPROM数据
return EEDR;
}
void EEPROM_Write_String(unsigned int uiAddress,unsigned char String[]){
unsigned char length;
length = strlen((char *)String);
if(length)
{
EEPROM_Write(*String++,uiAddress++);
}while(--length);
}
unsigned char EEPROM_Read_String(unsigned int uiAddress,unsigned int length){
unsigned char str;
if (length)
{
do
{
*str = EEPROM_Read(uiAddress++);
str++;
} while (--length);
}
return str;
}
int main(void)
{
unsigned char String;
EEPROM_Write_String(0,"ABCDe");
String = EEPROM_Read_String(0,5);
DDRA = 0xFF;
if (String == "ABCDe")
{
PORTA = 0xFF;
}else{
PORTA = 0x00;
}
while(1);
return 0;
}
页:
[1]