/***** 430 FLASH 字节读写程序 *************************/
430的数据RAM 与FLASH的读写
#define FLASH_ADDRESS 0x1000 //界说FLASH信息区地址B段
void flash_erase(unsigned char*);
void read_flash(unsigned char *pc_byte, unsigned char *array,unsigned char amount);
void write_flash(unsigned char *pc_byte,unsigned char *array,unsigned char amount);
//******************************************************************************
//FLASH段擦除
void flash_erase(unsigned char *pc_word)
{
while(FCTL3 & BUSY); //假如处于忙状况,则等候
FCTL3 = FWKEY ; //清出LOCK标志,解锁
FCTL1 = FWKEY + ERASE ; //答应段擦除
*pc_word = 0; //擦除..擦除..
while(FCTL3 & BUSY);
FCTL3 = FWKEY + LOCK ; //加锁
}
//******************************************************************************
//向FLASH信息区读出指定数量的字节数据
//unsigned int*pc_word :信息区数据指针
//unsigned char *array :读出数据寄存数据数组,8位长
//unsigned char amount :读操的数量,规模0-127
void read_flash(unsigned char *pc_byte, unsigned char *array,unsigned char amount)
{ unsigned char i;
for(i=0;i
{
*array = *pc_byte; //读数据,读数据时,flash地址主动加 1
array++; //接纳缓冲区地址加 1
}
}
//******************************************************************************
//向FLASH信息区写入指定数量的字节数据
//unsigned char *pc_byte 信息区数据指针
//unsigned char *array :读出数据寄存数据数组,8位长
//unsigned char amount :读操的数量,规模0-127
void write_flash(unsigned char *pc_byte,unsigned char *array, unsigned char amount)
{ unsigned char i;
_DINT();
while(FCTL3 & BUSY); //假如处于忙状况,则等候
FCTL3 = FWKEY ; //清出LOCK标志
FCTL1 = FWKEY + WRT ; //写操作,块编程,+ BLKWRT;
for(i=0;i
{
*pc_byte = *array;
//*pc_byte = num;
// num +=1;
array++; //发送缓冲区地址加 1
pc_byte++; //写flash时,地址人为加 1
while(!(FCTL3 & WAIT)); //假如处于忙状况,则等候 ,若用软件仿真,去掉 //这句子
}
FCTL1 = FWKEY; //写操作完结,铲除编程答应位 WRT,BLKWRT
while(FCTL3 & BUSY);
FCTL3 = FWKEY + LOCK;
}
/*
#define RAM_ADDRESS 0x300
__no_init volatile uchar XINHAO[3] @ 0x300; //类型 默许201
__no_init volatile uchar BdFlag @ 0x303; ////ff表明没有标定,00表明已标定置零01表明已标定1点.02表明已标定2点.03表明已标定3点
__no_init volatile uchar EDZHI @ 0x304; //额定值
__no_init volatile uchar CYSJ @ 0x305; //采样时刻
__no_init volatile uchar GJSJ @ 0x306; //主动关机时刻
__no_init volatile uchar YLDW @ 0x307; // 压力单位
__no_init volatile float Pyz @ 0x30A; // 置零后的皮压值
__no_init volatile float Bdxs[16] @ 0x310; // 标定系数
__no_init volatile float Bdzhi[16] @ 0x350; // 标定值
__no_init volatile float Bdnm[16] @ 0x390; // 标定内码0X0D0
void main(void)
{
volatile unsigned int i; // Use volatile to prevent removal
// by compiler optimization
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
FLL_CTL0 |= XCAP14PF; // Configure load caps
for (i = 0; i < 10000; i++); // Delay for 32 kHz crystal to
unsigned char *pc_flash; //界说字节指针变量 为字节读写
pc_flash = (unsigned char *) FLASH_ADDRESS; //为指针初始化 // stabilize
unsigned char *pc_ram; //界说字节指针变量 为字节读写
pc_ram = (unsigned char *) RAM_ADDRESS; //为指针初始化
while(1)
{
BdFlag = 1;
Bdxs[0]=3.14;
flash_erase(pc_flash); //段擦除
write_flash(pc_flash,pc_ram ,208); //写入指定字节数量
read_flash(pc_flash,pc_ram,208); //再读出方才写的字节
LPM3; // Enter low power mode 3
} */