uchar Flag = 0; //为1时表示接收到了@,如果紧接着收到R则发送EEPROM中的数据
uint EEpromAdd = 0; //存储在EEPROM中的地址
uchar temp[255],tempcnt = 0; //暂存数据
uchar temp1; //暂存串口接收到的数据
{
while ( EECR&0x02 ); //判断EEWE是否为0
EEAR = addr;
EEDR = val;
CLI();
EECR = EECR|0x04; //置EEMWE为1
EECR = EECR|0x02; //置EEWE为1
SEI();
}
{
while (num)
{
while ( EECR&0x01 ); //判断EEWE是否为0
EEAR = addr;
EECR = EECR|0x01; //置EERE为1
*val = EEDR;
addr++;
val++;
num--;
}
}
{
UCSRB = 0x00; //关串口
UCSRA = 0x02; //倍速模式 M16中文P151
UCSRC = BIT(URSEL) | 0x06; //写UCSRC寄存器,设定8个bit
UBRR = 206; //设定串口波特率为600
UCSRB = 0x98; //开串口
}
void UartRecvData(void)
{
temp1 = UDR;
RecvFlag = 1;
}
{
uint i;
for( i = 0; i < len; i++)
{
while(!(UCSRA&0x20)); //判断数据寄存器是否为空
UDR = SendData[i];
}
}
{
CLI(); //关全部中断
Uart0Init();
SEI(); //开全中断
}
uint j;
InitDevices();
while(j++);
EepromRead (255, 0, EepromData); //读取上次断电前程序存储的数据
UartTransmitData(EepromData, 255); //通过串口显示
while(1)11
{
if ( Flag == 2 )
{
Flag = 0;
EepromRead (EEpromAdd, 0, EepromData);//读取本次存储的数据,串口输出
UartTransmitData(EepromData, EEpromAdd);
}
if ( RecvFlag )
{
RecvFlag = 0;
if( temp1 == '@')
Flag = 1;
else if(((temp1 == 'R')||(temp1 == 'r'))&&( Flag == 1))//连续接收到@R
{
Flag = 2;
}
else
{
Flag = 0;
EepromWrite ( EEpromAdd++, temp1);
if ( EEpromAdd >= 255)
EEpromAdd = 0;
}
}
}