在线时间13 小时
UID300551
ST金币0
蝴蝶豆0
注册时间2010-1-4
初级会员
- 最后登录
- 2020-8-20
|
发表于 2011-8-12 09:45:07
|
显示全部楼层
a0a.1 0b0c
RE:stm8l的eeprom程序
void Init_EEPROM(void) //FLASH解锁
{
/*FLASH编程时间定义*/
FLASH_SetProgrammingTime(FLASH_ProgramTime_Standard);
/* Unlock flash Data memory */
FLASH_Unlock(FLASH_MemType_Data);
/* Wait until Data EEPROM area unlocked flag is set*/
while (FLASH_GetFlagStatus(FLASH_FLAG_DUL) == RESET)
{}
}
void __eeprom_write_16(unsigned short addr_eep,unsigned short data) //写一个双字节数据
{
FLASH_WaitForLastOperation(FLASH_MemType_Data);
FLASH_Unlock(FLASH_MemType_Data);
FLASH_ProgramByte(addr_eep, data/256);
FLASH_WaitForLastOperation(FLASH_MemType_Data);
FLASH_ProgramByte(addr_eep+1, data%256);
FLASH_WaitForLastOperation(FLASH_MemType_Data);
FLASH_Lock(FLASH_MemType_Data);
}
s16__eeprom_read_16(unsigned short addr_eep) //读一个双字节数据
{
s16 Save=0;
FLASH_WaitForLastOperation(FLASH_MemType_Data);
FLASH_Unlock(FLASH_MemType_Data);
Save=FLASH_ReadByte(addr_eep);
Save=Save*256;
FLASH_WaitForLastOperation(FLASH_MemType_Data);
Save+=FLASH_ReadByte(addr_eep+1);
FLASH_WaitForLastOperation(FLASH_MemType_Data);
FLASH_Lock(FLASH_MemType_Data);
return(Save);
} |
|