[P][P]本意是写一个计数器程序,数码管上不断显示计数值,掉电后充新上电则从掉电后数据开始接着计数。程序运行时,有时候掉电后重新上电能显示掉电值,有时候直接从0显示。[/P][P]调试时发现在flash写程序中,执行到*p=0这一句ACCVIFG置位,不知道置位原因,不知道问题是不是出在这。[/P][P]typedef unsigned char uchar;
typedef unsigned int uint;
#include <msp430x16x.h>[/P][P]#define uchar unsigned char
#define uint unsigned int[/P][P]#define wei_h P5OUT|= BIT5
#define wei_l P5OUT&= ~BIT5
#define duan_h P6OUT |= BIT6
#define duan_l P6OUT &= ~BIT6
//数码管7位段码:0--f
const unsigned char scandata[16] = {0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07, 0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
uchar value; // 8-bit value to write to segment A
uchar DataBuffer[128];
uchar val;
uchar tt;[/P][P]// Function prototypes
void write_SegA (uchar value);
void copy_A2B (void);
void delay(uint z);
void disp_smg (uchar number) ;
void init (void);
void read_SegA(void);
void main(void)
{ //初始化端口 P1DIR = 0XFF;P1OUT = 0XFF; P2DIR = 0XFF;P2OUT = 0XFF; P3DIR = 0XFF;P3OUT = 0XFF; P4DIR = 0XFF;P4OUT = 0XFF; P5DIR = 0XFF;P5OUT = 0XFF; P6DIR = 0XFF;P6OUT = 0XFF; P6DIR |= BIT2;P6OUT |= BIT2; //关电平转换 WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer init(); //write_SegA(value); read_SegA(); while(1) // Repeat forever { write_SegA(value); // Write segment A, increment value //read_SegA(); disp_smg (value); value++; if(value==200) value=0; }
}[/P][P]void write_SegA (uchar value)
{[/P][P] _DINT(); uchar *Flash_ptr; // Flash pointer uchar *p; //while ((FCTL3&BUSY)==BUSY);//等待忙状态结束 Flash_ptr = (uchar *) 0x1080; // Initialize Flash pointer p=(uchar *)0x1000; FCTL1 = FWKEY + ERASE; // Set Erase bit FCTL3 = FWKEY; // Clear Lock bit *Flash_ptr = 0; // Dummy write to erase Flash segment *p=0;//??ACCVIFG置位
//while ((FCTL3&BUSY)==BUSY);//等待忙状态结束 FCTL1 = FWKEY + WRT; // Set WRT bit for write operation *Flash_ptr = value; // Write value to flash val=*Flash_ptr; *p=0xaa; FCTL1 = FWKEY; // Clear WRT bit FCTL3 = FWKEY + LOCK; // Set LOCK bit _EINT();
}
void read_SegA(void)
{[/P][P] _DINT(); uchar *Flash_ptr; // Flash pointer uchar *p; Flash_ptr = (uchar *) 0x1080; // Initialize Flash pointer p= (uchar *) 0x1000; value=*Flash_ptr; tt=*p; _EINT(); if(tt!=0xaa) value=100;
}[/P][P]void disp_smg (uchar number)
{ unsigned int disp,i; unsigned int num[3]; num[0]=number/100; num[1]=number%100/10; num[2]=number%100%10; for(i=0;i<3;i++) { disp=num[I]; P4OUT = ~(1 << i); //输出位选信号 wei_h; wei_l; P4OUT = scandata[disp]; //输出段选信号 duan_h; duan_l; delay(1000); }
}[/P][P]void delay(uint z)
{ uint i; i = z; // Delay do (i--); while (i != 0);
}
void init (void)
{ FCTL2 = FWKEY + FSSEL0 + FN0; // MCLK/2 for Flash Timing Generator
}
[/P][/I][/P] |