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; while(FCTL3 & BUSY); //如果处于忙状态,则等待 FCTL3 = FWKEY ; //清出LOCK标志 FCTL1 = FWKEY + WRT ; //写操作,块编程,+ BLKWRT; { *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 WDTCTL = WDTPW + WDTHOLD; // Stop WDT while(1) {
}
_DINT();
for(i=0;i
/*
__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
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; //为指针初始化
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
} */
上一篇:MSP430 FLASH读写
下一篇:MSP430F14-直接IO口按键检处理程序
推荐阅读最新更新时间:2024-03-16 15:05