Exemplo n.º 1
0
/*!
 * \brief Bekapcsolásig hátralévő időt adja vissza.
 * \param void
 * \return remain.remain unsigned int
 */
unsigned int RemainGet(void) {
	signed char remain_temp;
	if(SetupGetMode() == MODE_ABS) {
		remain_temp = SetupGetOnTemp() - TempGet(NAPKOLLEKTOR_CH);
	} else {
		remain_temp = SetupGetOnTemp() -
					  (TempGet(NAPKOLLEKTOR_CH) - TempGet(MEDENCE_CH));
	}
	if(remain_temp >= 0) {
		remain.remain = TrendGet() * remain_temp;
		if(TrendGetUnit() == SEC) {
			if(remain.remain > 59) {
				remain.remain = remain.remain / 60;
				remain.remain_unit = MIN;
			} else {
				remain.remain_unit = SEC;
			}
		} else {
			remain.remain_unit = MIN;
		}
	} else {
		remain.remain = 0;
		remain.remain_unit = SEC;
	}
	return remain.remain;
}
Exemplo n.º 2
0
/*********************************************************** 
函数功能:停电模式循环
入口参数:
出口参数:
备注说明:1 空闲进入休眠,停显1屏,停电7天后关闭液晶显示
          2 定时1s唤醒,判断是否上电,喂狗,每分钟RTC温度补偿
          3 按键唤醒,低速运行一个轮显周期
          4 检测到上电后直接复位
***********************************************************/
uint16 PowerDowmMain(void)
{
	uint32 timer500ms=0;
	uint32 timer1000ms=0;
    int16 temp;
    volatile uint8 BatteryFlag = 0;
    volatile uint8 BatteryState;

	DRV_WD_FeedDog();
	//LvdGetManaul();		//设置LVD门限等
	while(1)
	{
		//按键中断唤醒
		if(scrKeyIntFlag)
		{
			scrKeyIntFlag=0;
			EXTI_DisableInt(EXTI_CH1);
            
			DRV_RTC_FlashTask();

			//adc
            DRV_ADC_On();
            
            DRV_ADC_StartTask();
            while(RESET != ADC12_GetScanStatusFlag(ADC12_UNIT0));
            DRV_ADC_StartTask();
            while(RESET != ADC12_GetScanStatusFlag(ADC12_UNIT0));
            DRV_ADC_StartTask();
            while(RESET != ADC12_GetScanStatusFlag(ADC12_UNIT0));
            DRV_ADC_StartTask();
            while(RESET != ADC12_GetScanStatusFlag(ADC12_UNIT0));
            DRV_ADC_StartTask();
            while(RESET != ADC12_GetScanStatusFlag(ADC12_UNIT0));
            
            DRV_ADC_Off();    
			BatteryState = BattLowStateGet();

			if(BatteryState == 0)
			{
				BatteryFlag = 0;
				PowerSleepWakeInit();
				//按键唤醒主循环
				while(1)
				{
					if(runMe)
					{
						//5ms任务
						runMe=0;
						timer500ms++;
						timer1000ms++;
						DRV_WD_FeedDog();
						if(FM3_GPIO->PDIR1&= IO_PINx3)
						{//上电外部中断唤醒
							if(PowerUpDetect())
							{
								PowerWakeSleepInit();//设置唤醒源,退出低速运行
								break;			
							}
						}
						Key_Scr_DetectPowerDown_Task();//轮显按键驱动
						//CoverDetectProcess();
						//EventBatteryUpdateStateFlagProcess();
						//500ms任务
						if(timer500ms>100)
						{
							timer500ms=0;
							//DRV_RTC_FlashTask();
							//Clock_CheckDST();
						}
						DRV_RTC_FlashTask();
						//1000ms任务
						if(timer1000ms>200)
						{
							timer1000ms=0;
                        	PowerDownDisplayAlarmPro();
                        	//LCD_Flag_Driver_Task();
                        	Disp_Auto_Cycle_Task();	//显示
							if(wakeUpTimer)		//定时回到休眠
							{
								wakeUpTimer--;
							}
							else
							{
								PowerWakeSleepInit();//设置唤醒源,退出低速运行
								break;
							}
						}
					}
				}	
			}
			else
			{
				DRV_LCD_Uninit();
			}
		}
		
		//1s定时中断唤醒
		if(SecFlag==1)
		{
			SecFlag=0;           
		}
        
        //1min定时中断唤醒
        if(MinFlag==1)
        {
            MinFlag=0;
                   
            //adc
            DRV_ADC_On();
          
            DRV_ADC_StartTask();
            while(RESET != ADC12_GetScanStatusFlag(ADC12_UNIT0));
            DRV_ADC_StartTask();
            while(RESET != ADC12_GetScanStatusFlag(ADC12_UNIT0));
            DRV_ADC_StartTask();
            while(RESET != ADC12_GetScanStatusFlag(ADC12_UNIT0));
            DRV_ADC_StartTask();
            while(RESET != ADC12_GetScanStatusFlag(ADC12_UNIT0));
            DRV_ADC_StartTask();
            while(RESET != ADC12_GetScanStatusFlag(ADC12_UNIT0));
          
            DRV_ADC_Off();
            //RTC温度补偿
            TempGet(&temp, 1);                    
            CalcPPM(temp);
            DRV_RTC_CalcSecDeviation();  //停电计算秒的误差
            
            if(BattLowStateGet())//电池
            {      
               SetSegment(SEG_battery2,0);
            }
            else
            {
           	   SetSegment(SEG_battery2,1); 
            }
			RefreshLCD();
            //电池电压检测
			BatteryState = BattLowStateGet();
			if(BatteryState == 1)
          	{
				if(BatteryFlag == 0)
				{
					Feed_watchdog();
					BatteryFlag =1;
					SleepDispTimer = 0;
				}
          	}
          	else if(BatteryFlag == 1)
          	{
                *(volatile unsigned long*)(0xE000ED0C)=0x05FA0004;
				while(1);                          //20140710加上
          	}
		    //停电停显定时          
		    if(SleepDispTimer)
		    {
			   SleepDispTimer--;
		    }
		    else
		    {
			   DRV_LCD_Uninit();	//关闭LCD
		    }  
        }

		//p13上电预判//尽量缩短检测时间
		if(FM3_GPIO->PDIR1&= IO_PINx3)
		{
			if(PowerUpDetect())
			{
				//if(POWER_UP_INIT_SUCESS == PowerUpInit())
				//{
				//	return POWER_UP_INIT_SUCESS;	//回到主循环
				//}
				//else
				//{
				//	PowerDownInit();
				//	Feed_watchdog();
					//LvdGetManaul();		//设置LVD门限等
				//}
				*(volatile unsigned long*)(0xE000ED0C)=0x05FA0004;
				while(1);                       //20140710加上
			}
		}
		//休眠
		if(BatteryState == 1)
        {
             LowPwrCon_GoToStandByMode(STB_RTCMode,STB_IO_KEEP);
        }
        else
        {
             LowPwrCon_GoToStandByMode(STB_TimerMode,STB_IO_KEEP);	
        }
		Feed_watchdog();
	}	
}