|
下面贴上关于Flash的代码
#include "msp430G2553.h"
unsigned int SegAddr = 0;
unsigned int SegPre = 0;
unsigned char Flash_Init(unsigned char Div,unsigned char Seg)
{
if(Div < 1)
{
Div = 1;
}
if(Div > 64)
{
Div = 64;
}
FCTL2 = FWKEY + FSSEL_2 + Div -1;
SegPre = Seg;
if(Seg <= 31)
{
SegAddr = 0xFFFF - (Seg + 1) * 512 +1;
return (1);
}
switch(Seg)
{
case 'A': case 'a': SegAddr = 0x10C0;break;
case 'B': case 'b': SegAddr = 0x1080;break;
case 'C': case 'c': SegAddr = 0x1040;break;
case 'D': case 'd': SegAddr = 0x1000;break;
default: SegAddr = 0x20FF;return (0);
}
return (1);
}
unsigned char Flash_ReadChar(unsigned int Addr)
{
unsigned char Data = 0;
unsigned int *Ptr_SegAddr,temp = 0;
if((SegPre <= 31 && Addr >= 512) || (SegPre > 31 && Addr >= 64))
{
return 0;
}
temp = SegAddr + Addr;
Ptr_SegAddr = (void*)temp;
Data = *(Ptr_SegAddr);
return (Data);
}
char Flash_Direct_WriteChar(unsigned int Addr,unsigned char Data)
{
unsigned int temp = 0;
unsigned char *Ptr_SegAddr;
if((SegPre <= 31 && Addr >= 512) || (SegPre > 31 && Addr >= 64))
{
return 0;
}
temp = SegAddr + Addr;
Ptr_SegAddr = (unsigned char*)temp;
FCTL1 = FWKEY + WRT;
FCTL3 = FWKEY;
_disable_interrupts();
*Ptr_SegAddr = Data;
while(FCTL3 & BUSY);
_enable_interrupts();
FCTL1 = FWKEY;
FCTL3 = FWKEY + LOCK;
return 1;
}
|
|