下面的代码解决了我的疑问
void EEPOM_Test_AddrChange(void)
{
u8 i=0;
u8 j=0;
Address_Channel_1=STORE_Resistance_Address_Channel_1;
Address_Channel_2=STORE_Resistance_Address_Channel_2;
Address_Channel_3=STORE_Resistance_Address_Channel_3;
DETECT_Address=STORE_RT_DETECT_Address;
TEMPER_Address=STORE_RT_TEMPER_Address;//定义了五个存储地址
i = (u8)AD_Get_Average(AD_CHANNEL_0); //ADC采集值做随机数
while(1)
{
EE24c02_transfer(WRITE,Address_Channel_1,&i,1);//写随机数
EE24c02_transfer(READ,Address_Channel_1,&j,1);//读随机数
if(i==j)//E2POM没问题
{
#ifdef DEBUG
SERIAL_Putchar(Address_Channel_1);//如果读写正确 证明此字节擦写正常
#endif
break;//跳出循环
}
else
{
#ifdef DEBUG
SERIAL_Putchar(Address_Channel_1);
SERIAL_Putchar(i);
SERIAL_Putchar(j);
#endif
Address_Channel_1 += 0x14;//如果擦写不正常 地址+20做为新地址
}
}
i = (u8)AD_Get_Average(AD_CHANNEL_0); //产生0-127的随机数
while(1)
{
EE24c02_transfer(WRITE,Address_Channel_2,&i,1);
EE24c02_transfer(READ,Address_Channel_2,&j,1);
if(i==j)//E2POM没问题
{
#ifdef DEBUG
SERIAL_Putchar(Address_Channel_2);
#endif
break;
}
else
{
#ifdef DEBUG
SERIAL_Putchar(Address_Channel_2);
#endif
Address_Channel_2 += 0x14;
}
}
i = (u8)AD_Get_Average(AD_CHANNEL_0); //产生0-127的随机数
while(1)
{
EE24c02_transfer(WRITE,Address_Channel_3,&i,1);
EE24c02_transfer(READ,Address_Channel_3,&j,1);
if(i==j)//E2POM没问题
{
#ifdef DEBUG
SERIAL_Putchar(Address_Channel_3);
#endif
break;
}
else
{
#ifdef DEBUG
SERIAL_Putchar(Address_Channel_3);
#endif
Address_Channel_3 += 0x14;
}
}
i = (u8)AD_Get_Average(AD_CHANNEL_0);//产生0-127的随机数
while(1)
{
EE24c02_transfer(WRITE,DETECT_Address,&i,1);
EE24c02_transfer(READ,DETECT_Address,&j,1);
if(i==j)//E2POM没问题
{
#ifdef DEBUG
SERIAL_Putchar(DETECT_Address);
#endif
break;
}
else
{
#ifdef DEBUG
SERIAL_Putchar(DETECT_Address);
#endif
DETECT_Address += 0x14;
}
}
i = (u8)AD_Get_Average(AD_CHANNEL_0); //产生0-127的随机数
while(1)
{
EE24c02_transfer(WRITE,TEMPER_Address,&i,1);
EE24c02_transfer(READ,TEMPER_Address,&j,1);
if(i==j)//E2POM没问题
{
#ifdef DEBUG
SERIAL_Putchar(TEMPER_Address);
#endif
break;
}
else
{
#ifdef DEBUG
SERIAL_Putchar(TEMPER_Address);
#endif
TEMPER_Address += 0x14;
}
}
}