OpenVINOTM,给你看得见的未来!>>
电子产品世界 » 论坛首页 » 综合技术 » 基础知识 » FLASH 保存参数到FLASH中去

共2条 1/1 1 跳转至

FLASH 保存参数到FLASH中去

院士
2006-12-22 22:43:00    评分
FLASH 保存参数到FLASH中去



关键词: FLASH     保存     参数     中去    

院士
2006-12-22 22:43:00    评分
2楼
问 版主:你好
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 跳转至

回复

匿名不能发帖!请先 [ 登陆 注册 ]