我在用MSP430单片机的FLASH模块做掉电不丢失 参考很多资料 编了个程序 结果运行 等不到正确结果 请高人指点啊
程序如下::
我在用MSP430单片机的FLASH模块做掉电不丢失 参考很多资料 编了个程序 结果运行 等不到正确结果 请高人指点啊
程序如下::
#include <msp430x16x.h>
typedef unsigned int uint;
typedef unsigned char uchar;
uchar c0,*Flash_ptr;
void write_SegA (uchar c0)
{_DINT();
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++ = c0; // Write value to flash
}
_NOP();
FCTL1 = FWKEY; // Clear WRT bit
FCTL3 = FWKEY + LOCK; // Set LOCK bit
_EINT();
}
// main函数
void main(void)
{
WDTCTL = WDT_ADLY_1000;
FCTL2 = FWKEY + FSSEL0 + FN0; // MCLK/2 for Flash Timing Generator
// Flash_ptr = (uchar *) 0x1080; // Initialize Flash pointer
IE1|=WDTIE;
init_LCD();
c0=*Flash_ptr;
_EINT();
while(1)
{
_BIS_SR(CPUOFF);
_NOP();
}
}
#pragma vector=WDT_VECTOR
__interrupt void watchdog_timer (void)
{ c0=*Flash_ptr;
_NOP();
c0=c0+1;
if(c0==10) c0=0;
px=16; py=88; width=8; write(px,py,c0);
_NOP();
write_SegA(c0);
}
小弟联系QQ281050616 拜托了····