我采用MSP430F2418,看门狗作为定时器,每个1s中断,在中断函数中更新两个tick,时间分别隔45s设置时钟显示更新标识,隔300s设置测量电池电压标识,主程序进入低功耗模式,部分代码如下:
while(1)
{
_BIS_SR(LPM3_bits + GIE); // Enter LPM3 w/ interrupt
if (realtime_update_flag ==1)
{
realminute_before = (realtime[1]/16)*10 +(realtime[1]%16
Get_Realtime(realtime);
virtual_reg[v_systemtime_year] = realtime[6];
virtual_reg[v_systemtime_month] =realtime[5];
virtual_reg[v_systemtime_data] =realtime[4];
virtual_reg[v_systemtime_hour] =realtime[2];
virtual_reg[v_systemtime_minute] =realtime[1];
virtual_reg[v_systemtime_second] =realtime[0];
realminute = (realtime[1]/16)*10 +(realtime[1]%16);
if(realminute_before !=realminute) //高于1分钟的相关任务处理
{
Display_realtime_monthdate(realtime[5],realtime[4]);
Display_realtime_hourminute (realtime[2],realtime[1]);
}
realtime_update_flag = 0;
}
if(testbattery_flag == 0)
{
MeasurePower();
if(batterystatus != 5)
{
Display_batterystatus(batterystatus);
}
else
{
Display_batterystatus(batterystatus-1);
}
}
}
#pragma vector=WDT_VECTOR
__interrupt void watchdog_timer(void)
{
systemtick++;
realtime_updata_number++;//时钟更新
if( realtime_updata_number ==45) //达1分钟 退出休眠状态
{
realtime_updata_number = 0;
realtime_update_flag = 1;
}
if((systemtick %300) == 0)//每隔5分钟测量一次电池电压
{
testbattery_flag = 1;
systemtick = 0;
}
__bic_SR_register_on_exit(LPM3_bits);
}
现在情况是如果把两个功能分开,都能可靠运行。单像上面一起处理,系统出现复位现象,不知是何原因,望指教 |