共2条
1/1 1 跳转至页
INFO,FLASH 【讨论】INFO FLASH的使用
问
版主:我用f149片子,资料上说它有256个字节的INFO FLASH,那么我是否可以拿来保存一些保存数据,当再次上电时我能读出这些数据呢?请问在IAR WORKBENCH里怎么定义呢?谢谢!
答 1:
大家快过来啊,帮我顶一下
答 2:
可以保存数据,且掉电不丢失
但每次写之前必须擦除 答 3: 那么请问该怎么定义呢 在IAR workbench里? 答 4: 有一个参考例子,看一下吧
//****************************************************************************
// MSP-FET430x110 Demo - Flash In-System Programming
//
// Description; This program first erases flash seg A, then it increments all
// values in seg A, then it erases seg B, then copies seg A to seg B.
// Assumed MCLK 550kHz - 900kHz.
//
// MSP430F1121
// -----------------
// /|\| XIN|-
// | | |
// --|RST XOUT|-
// | |
//
// M. Mitchell
// Texas Instruments, Inc
// August 2002
// Built with IAR Embedded Workbench Version: 1.25A
// December 2003
// Updated for IAR Embedded Workbench Version: 2.21B
//******************************************************************************
//******************************************************************************
#include <MSP430x11x1.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
} 答 5: 谢谢了先
但每次写之前必须擦除 答 3: 那么请问该怎么定义呢 在IAR workbench里? 答 4: 有一个参考例子,看一下吧
//****************************************************************************
// MSP-FET430x110 Demo - Flash In-System Programming
//
// Description; This program first erases flash seg A, then it increments all
// values in seg A, then it erases seg B, then copies seg A to seg B.
// Assumed MCLK 550kHz - 900kHz.
//
// MSP430F1121
// -----------------
// /|\| XIN|-
// | | |
// --|RST XOUT|-
// | |
//
// M. Mitchell
// Texas Instruments, Inc
// August 2002
// Built with IAR Embedded Workbench Version: 1.25A
// December 2003
// Updated for IAR Embedded Workbench Version: 2.21B
//******************************************************************************
//******************************************************************************
#include <MSP430x11x1.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
} 答 5: 谢谢了先
共2条
1/1 1 跳转至页
回复
有奖活动 | |
---|---|
【有奖活动】分享技术经验,兑换京东卡 | |
话不多说,快进群! | |
请大声喊出:我要开发板! | |
【有奖活动】EEPW网站征稿正在进行时,欢迎踊跃投稿啦 | |
奖!发布技术笔记,技术评测贴换取您心仪的礼品 | |
打赏了!打赏了!打赏了! |