请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。
部件号:MSP430G2553 工具/软件:Code Composer Studio
您好,
我想知道如何将浮点值存储在闪存中,存储为2个字或4个字节?
谢谢大家。
This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
工具/软件:Code Composer Studio
您好,
我想知道如何将浮点值存储在闪存中,存储为2个字或4个字节?
谢谢大家。
以下是将char数据写入内存的示例
void WriteToFlash (char*地址,char val)
{
char* flash_ptr;
FCTL3 = FWKEY;
flash_ptr =地址; //初始化闪存指针
While (FCTL3 & Busy);
FCTL1 = FWKEY + WRT;
*FLASH_PTR = val;
While (FCTL3 & Busy);
FCTL1 = FWKEY; //清除WRT位
FCTL3 = FWKEY + LOCK; //设置锁定位
}
另一个写长数据的例子是:
WriteFWToFlash(((short*)MEM_SLOPE _H,(short)(wt_slope & 0xffff);// Slope WriteShortToFlash((((short*)MEM_SLOT_L,(short)((wt_slope >>16)& 0xff));// ShortPTR WriteShortToFlash(short*地址 ,short_FLASH =FLASH =短距离FLASH //初始化闪存指针 While (FCTL3 & Busy); FCTL1 = FWKEY + WRT; *FLASH_PTR = val; While (FCTL3 & Busy); FCTL1 = FWKEY; //清除WRT位 FCTL3 = FWKEY + LOCK; //设置锁定位 }
我想知道如何将浮点写入内存
感谢你的帮助
好的。 我认为以下内容应该有效。
斯蒂芬
float var1 = 3.1.4159万 ;
unsigned long int wt_slope;
int main(void){
wt_slope =*(无符号长整型*)&var1;
WriteShortToFlash(((Short*)MEM_SLOT_H,(Short)(wt_slope & 0xff));//斜率
WriteShortToFlash(((short*)MEM_SLOT_L,(short)((wt_slope >>16)& 0xff));//斜率
}