共2条
1/1 1 跳转至页
FLASH 保存参数到FLASH中去
问
版主:你好
在MSP430F149中的SegmentA 信息存储区,是不是可以供给用户当作为参数使用,我相把修好的参数存入在FLASHA中, 你有没有擦用FLASH和写入FLASH例程,是否能提供给我.最好是用C语言的, 答 1: 请参见下面例程:
#include <MSP430x14x.h>
char value; // 8-bit value to write to segment A
// Function prototypes
void write_SegA (char value);
void copy_A2B (void);
void main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
FCTL2 = FWKEY + FSSEL0 + FN0; // MCLK/2 for Flash Timing Generator
value = 0; // initialize value
while(1) // Repeat forever
{
write_SegA(value++); // Write segment A, increment value
copy_A2B(); // Copy segment A to B
}
}
void write_SegA (char value)
{
char *Flash_ptr; // Flash pointer
unsigned int i;
Flash_ptr = (char *) 0x1080; // Initialize Flash pointer
FCTL1 = FWKEY + ERASE; // Set Erase bit
FCTL3 = FWKEY; // Clear Lock bit
*Flash_ptr = 0; // Dummy write to erase Flash segment
FCTL1 = FWKEY + WRT; // Set WRT bit for write operation
for (i=0; i<128; i++)
{
*Flash_ptr++ = value; // Write value to flash
}
FCTL1 = FWKEY; // Clear WRT bit
FCTL3 = FWKEY + LOCK; // Reset LOCK bit
}
void copy_A2B (void)
{
char *Flash_ptrA; // Segment A pointer
char *Flash_ptrB; // Segment B pointer
unsigned int i;
Flash_ptrA = (char *) 0x1080; // Initialize Flash segment A pointer
Flash_ptrB = (char *) 0x1000; // Initialize Flash segment B pointer
FCTL1 = FWKEY + ERASE; // Set Erase bit
FCTL3 = FWKEY; // Clear Lock bit
*Flash_ptrB = 0; // Dummy write to erase Flash segment B
FCTL1 = FWKEY + WRT; // Set WRT bit for write operation
for (i=0; i<128; i++)
{
*Flash_ptrB++ = *Flash_ptrA++; // copy value segment A to segment B
}
FCTL1 = FWKEY; // Clear WRT bit
FCTL3 = FWKEY + LOCK; // Reset LOCK bit
} 答 2: 谢谢你版主 答 3: 引用: 答 4: FlashV= (char *) 0x1080
变量名 强制转换类型 目标地址 答 5: 谢谢你,我可以用了
在MSP430F149中的SegmentA 信息存储区,是不是可以供给用户当作为参数使用,我相把修好的参数存入在FLASHA中, 你有没有擦用FLASH和写入FLASH例程,是否能提供给我.最好是用C语言的, 答 1: 请参见下面例程:
#include <MSP430x14x.h>
char value; // 8-bit value to write to segment A
// Function prototypes
void write_SegA (char value);
void copy_A2B (void);
void main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
FCTL2 = FWKEY + FSSEL0 + FN0; // MCLK/2 for Flash Timing Generator
value = 0; // initialize value
while(1) // Repeat forever
{
write_SegA(value++); // Write segment A, increment value
copy_A2B(); // Copy segment A to B
}
}
void write_SegA (char value)
{
char *Flash_ptr; // Flash pointer
unsigned int i;
Flash_ptr = (char *) 0x1080; // Initialize Flash pointer
FCTL1 = FWKEY + ERASE; // Set Erase bit
FCTL3 = FWKEY; // Clear Lock bit
*Flash_ptr = 0; // Dummy write to erase Flash segment
FCTL1 = FWKEY + WRT; // Set WRT bit for write operation
for (i=0; i<128; i++)
{
*Flash_ptr++ = value; // Write value to flash
}
FCTL1 = FWKEY; // Clear WRT bit
FCTL3 = FWKEY + LOCK; // Reset LOCK bit
}
void copy_A2B (void)
{
char *Flash_ptrA; // Segment A pointer
char *Flash_ptrB; // Segment B pointer
unsigned int i;
Flash_ptrA = (char *) 0x1080; // Initialize Flash segment A pointer
Flash_ptrB = (char *) 0x1000; // Initialize Flash segment B pointer
FCTL1 = FWKEY + ERASE; // Set Erase bit
FCTL3 = FWKEY; // Clear Lock bit
*Flash_ptrB = 0; // Dummy write to erase Flash segment B
FCTL1 = FWKEY + WRT; // Set WRT bit for write operation
for (i=0; i<128; i++)
{
*Flash_ptrB++ = *Flash_ptrA++; // copy value segment A to segment B
}
FCTL1 = FWKEY; // Clear WRT bit
FCTL3 = FWKEY + LOCK; // Reset LOCK bit
} 答 2: 谢谢你版主 答 3: 引用: 答 4: FlashV= (char *) 0x1080
变量名 强制转换类型 目标地址 答 5: 谢谢你,我可以用了
共2条
1/1 1 跳转至页
回复
有奖活动 | |
---|---|
【有奖活动】分享技术经验,兑换京东卡 | |
话不多说,快进群! | |
请大声喊出:我要开发板! | |
【有奖活动】EEPW网站征稿正在进行时,欢迎踊跃投稿啦 | |
奖!发布技术笔记,技术评测贴换取您心仪的礼品 | |
打赏了!打赏了!打赏了! |