dirtwillfly 发表于 2014-8-25 11:01
写flash
版主帮我再看下,怎么这个S_Data.address老是被改变啊,怎么处理
//存储数据 更改地址和ID
typedef struct{
char Id_Data[5];
char address;
}Data_Struct;
void ReadFlash(void *pData,unsigned char *pInfo,char n)//读数据
{
memcpy(pData,pInfo,n);
}
void WriteFlash(unsigned char *pInfo,void *pData,char n)//写数据
{
_DINT();
FCTL3 = FWKEY;//清除"LOCK"标志
FCTL1 = FWKEY + ERASE;
*pInfo = 0; //擦出
FCTL1 = FWKEY + WRT;//准备写
memcpy(pInfo,pData,n);
FCTL1 = FWKEY;
FCTL3 = FWKEY + LOCK;//LOCK
_EINT();
}
然后这是调用的
void ADD_ID_Init(void)
{
S_Data.address = 0x80;//地址
WriteFlash((unsigned char *)0x1020,&S_Data.address,1);
S_Data.Id_Data[0] = 0x11;
S_Data.Id_Data[1] = 0x0E;
S_Data.Id_Data[2] = 0xEE;
S_Data.Id_Data[3] = 0x09;
S_Data.Id_Data[4] = 0xD5;
WriteFlash((unsigned char *)0x1010,S_Data.Id_Data,5);//仿真过了这个之后FLASH里的S_Data.address就变成0XFF了
} |