资源简介
关于MSP430单片机内部FLASH应用例程(读、写、擦除和保存数据),自己已经调试完成,希望可以帮到大家。
代码片段和文件信息
//****************************************************************************
// MSP-FET430P140 Demo - Flash In-System Programming Copy SegA to SegB
//
// 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 ACLK 3686400/10 kHz.
// //* Set Breakpoint on NOP in the Mainloop to avoid Stressing Flash *//
//
// MSP430F149
// -----------------
// /|\| XIN|-
// | | |
// --|RST XOUT|-
// | |
//
// M. Mitchell
// Texas Instruments Inc.
// Feb 2005
// Built with IAR embedded Workbench Version: 3.21A
//******************************************************************************
#include
typedef unsigned char uchar;
typedef unsigned int uint;
uchar value; // 8-bit value to write to segment A
uchar DataBuffer[128];
// Function prototypes
void write_SegA (uchar value);
void copy_A2B (void);
void send(void);
void Com2_Init(void);
void TA_Init(void);
void main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
FCTL2 = FWKEY + FSSEL_0 + FN3 + FN0; // ACLK/10 for Flash Timing Generator (range from ~ 257 kHz to ~ 476 kHz)
value = 0; // Initialize value
Com2_Init();
TA_Init();
_BIS_SR(LPM3_bits + GIE); // LPM0 ADC12_ISR will force exit
}
// Timer A0 interrupt service routine
#pragma vector=TIMERA0_VECTOR
__interrupt void Timer_A (void)
{
write_SegA(value++); // Write segment A increment value
send();
copy_A2B(); // Copy segment A to B
_NOP(); // SET BREAKPOINT HERE
}
void write_SegA (uchar value)
{
uchar *Flash_ptr; // Flash pointer
uint i;
Flash_ptr = (uchar *) 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 = FW
- 上一篇:dubbo入门的demo
- 下一篇:单层、双层A型USB母口的PCB封装
评论
共有 条评论