2019-03-24 11:21发布
scott123 发表于 2014-7-10 17:48 印象中 是flash,不像是eeprom 只能重覆讀寫幾千次,eeprom才能到百萬次
最多设置5个标签!
#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;
}
也就是说不推荐用内部Flash?
印象中是FAE跟我說的
你應該先驗証這一個答案的真假
我只是寫好玩的,沒有去測試FLASH壽命
如果答案是真的
那可能就真的要儲存在EEPROM了
一周热门 更多>