当我把定义的一个数组写入FLASH里时,只能写入第一个数,后面的数都写不进去了,程序如下,那些路过的高手解答一下吧!!感激不尽!!!
#include "msp430x16x.h"
#define uint unsigned int
#define uchar unsigned char
#define Flase_add 0x5000
void Erasure_Flash_Segment(uint add);//段擦除
void Writ_Flash_Word(uchar data,uint add);//字写
void Bcs_Init(void);//系统时钟初始化
void Flash_Init(void);//flase 初始化
uchar DataBuff[6]={1,2,3,4,5,6};
void main()
{
WDTCTL = WDTPW + WDTHOLD;//stup wdt
Bcs_Init();
Flash_Init();
uchar i;
uint *Flase_p;
uchar *Data_p;
*Flase_p = Flase_add;
Data_p = &DataBuff[0];
Erasure_Flash_Segment(Flase_add);
Writ_Flash_Word(1,0x5200);
for(i = 0; i < 6; i++)
{
Writ_Flash_Word(*Data_p,*Flase_p);
Data_p++;
Flase_p++;
}
Writ_Flash_Word(1,0x52a0);
while(1);
}
void Bcs_Init(void)
{
uchar i;
BCSCTL1 &= ~XT2OFF;//open oxt2
do
{
IFG1 &= ~OFIFG;//clear ofifg
for(i = 0xff; i > 0; i--);//wait
}
while(IFG1 & OFIFG);
BCSCTL2 |= SELM_2 + SELS + DIVS_3;//mclk = xt2 = smclk/8
}
void Flash_Init(void)
{
FCTL2 = FWKEY + FSSEL_2 + FN2;//fclk = smclk/4=250k
}
void Erasure_Flash_Segment(uint add)
{
uint *ps;
ps = (uint *)add;
while(FCTL3 & BUSY); //flash是否忙
FCTL1 = FWKEY + ERASE; //擦除
FCTL3 = FWKEY; //clear lock
*ps = 0x00; //erasur
while(FCTL3 & BUSY); //flash是否忙
FCTL3 = FWKEY + LOCK; //open lock
}
void Writ_Flash_Word(uchar data,uint add)
{
uchar * pw;
pw = (uchar *)add;
while(FCTL3 & BUSY); //flash是否忙
FCTL1 = FWKEY + WRT; //word writ
FCTL3 = FWKEY; //clear lock
* pw = data; //writ
FCTL1 = FWKEY; //clear writ
FCTL3 = FWKEY + LOCK; //open lock
while(FCTL3 & BUSY); //flash是否忙
} |