原谅我做的很简单,偷了一下懒,只是将一个一位int型数据存入flash,关机又上电后重新读出,并没有做什么深入的尝试。

void Erase_SegC(void);
void write_SegC(int value);
int Read_SegC(void);
void write_SegC(int value)
{
int * Flash_ptr; // Initialize Flash pointer
Flash_ptr = (int *) 0x1880;
FCTL3 = FWKEY; // Clear Lock bit
FCTL1 = FWKEY+ERASE; // Set Erase bit
*Flash_ptr = 0; // Dummy write to erase Flash seg
FCTL1 = FWKEY+WRT; // Set WRT bit for write operation
*Flash_ptr++ = value; // Write value to flash
FCTL1 = FWKEY; // Clear WRT bit
FCTL3 = FWKEY+LOCK; // Set LOCK bit
}
void Erase_SegC(void)
{
int *Flash_ptrC = (int *)0x1880; // Initialize Flash pointer
FCTL3 = FWKEY; // Clear Lock bit
FCTL1 = FWKEY+MERAS; // Set Bank Erase bit
*Flash_ptrC = 0; // Dummy erase byte
FCTL3 = FWKEY+LOCK; // Set LOCK bit
}
int Read_SegC(void)
{
int tmp;
int *Flash_ptrC;
Flash_ptrC = (int *) 0x1880; // Initialize Flash segment C ptr
__disable_interrupt(); // 5xx Workaround: Disable global
// interrupt while erasing. Re-Enable
// GIE if needed
FCTL3 = FWKEY; // Clear Lock bit
FCTL1 = FWKEY+ERASE; // Set Erase bit
FCTL1 = FWKEY+WRT; // Set WRT bit for write operation
tmp=*Flash_ptrC; // copy value segment C to seg D
FCTL1 = FWKEY; // Clear WRT bit
FCTL3 = FWKEY+LOCK; // Set LOCK bit
return tmp;
}