uint32_t EEP_Read_Byte(uint32_t Address)
{
uint32_t Temp = *(__IO uint32_t *)Address;
return Temp;
}
void EEPROM_Init(void)
{
uint8_t i,Flag;
uint32_t Address;
uint32_t Temp[4];
Address = EEP_Start_Address;
Temp[0] = *(__IO uint32_t *)Address;
Flag = (Temp[0] & 0xff000000) >> 24;
if(Flag != 0x55)
{
FLASH_Unlock();
FLASH_ClearFlag(FLASH_FLAG_EOP|FLASH_FLAG_PGERR|FLASH_FLAG_WRPERR);
FLASH_ErasePage(EEP_Start_Address);
Address = EEP_Start_Address;
FLASH_ProgramWord(Address,0x55050505);
for(i = 0;i < 3;i++)
{
Address += 4;
FLASH_ProgramWord(Address,((170 << 16) + 170));
}
FLASH_Lock();
}
Address = EEP_Start_Address;
for(i = 0;i < 4;i++)
{
Temp[i] = *(__IO uint32_t *)Address;
Address += 4;
}
Set_Time_Heat[0] = (Temp[0] & 0x000000ff);
Set_Time_Heat[1] = (Temp[0] & 0x0000ff00) >> 8;
Set_Time_Heat[2] = (Temp[0] & 0x00ff0000) >> 16;
Set_Temp[0] = Temp[1] >> 16;
Set_Temp[1] = Temp[1] & 0xffff;
Set_Temp[2] = Temp[2] >> 16;
Set_Temp[3] = Temp[2] & 0xffff;
Set_Temp[4] = Temp[3] >> 16;
Set_Temp[5] = Temp[3] & 0xffff;
}
//====================================================================
void EEPROM_Write_Byte(void)
{
uint8_t i;
uint32_t Address,Temp;
FLASH_Unlock();
FLASH_ClearFlag(FLASH_FLAG_EOP|FLASH_FLAG_PGERR|FLASH_FLAG_WRPERR);
FLASH_ErasePage(EEP_Start_Address);
Address = EEP_Start_Address;
Temp = ((0x55 << 24) + \
(Set_Time_Heat[2] << 16) + \
(Set_Time_Heat[1] << 8 ) + \
Set_Time_Heat[0]);
FLASH_ProgramWord(Address,Temp);
for(i = 0;i < 3;i++)
{
Address += 4;
FLASH_ProgramWord(Address,((Set_Temp[i * 2] << 16) + Set_Temp[(i * 2) + 1]));
}
FLASH_Lock();
}
|