//参数:wAddr为地址,范围0x1000~0xFFFF
void ReadFlash(U16 wAddr,U8 *bBuf,U8 bLen)
{
while (bLen--)
*bBuf++=*(U8 *)wAddr++;
return;
}
void WriteFlash(U16 wAddr,U8 *bBuf,U8 bLen)
{
U8 reg1,reg2;
reg1=_BIC_SR(GIE);
reg2=IE1;IE1=0;
while (bLen--) {
while (FCTL3&BUSY);
FCTL3 = FWKEY;
FCTL1 =FWKEY+WRT;
*(U8 *)wAddr++=*bBuf
while(FCTL3&BUSY);
FCTL1 = FWKEY;
FCTL3 = FWKEY+LOCK;
}
if(reg1&GIE) _BIS_SR(GIE);
IE1=reg2;
return;
}
void EraseSectorFlash(U16 wAddr)
{
U8 reg1,reg2;
reg1=_BIC_SR(GIE);
reg2=IE1;
IE1=0;
while(FCTL3&BUSY);
FCTL3 = FWKEY;
FCTL1 = FWKEY+ERASE;
*(U8 *)wAddr=0;
while(FCTL3&BUSY);
FCTL1 = FWKEY;
FCTL3 = FWKEY+LOCK;
if(reg1&GIE) _BIS_SR(GIE);
IE1=reg2;
return;
} |