int main()
{
#ifdef DEBUG
debug();
#endif
Configuration();
deletef("cmd.dat");
creatf("cmd.dat",0,0);
GPIO_SetBits(GPIOB, GPIO_Pin_12); //给GPS供电打开
USART_ITConfig(USART3,USART_IT_RXNE , ENABLE);
Delay1(30000);
while(1)
{
GPSdataformat(); //用串口收到GPS数据,并且写入 SRAM
if(count>400)
{
writef("cmd.dat",GPS,count); //写入SD卡SRAM的数据
Delay1(100);
count=0;
}
else
{
Delay1(100);
}
//Delay1(5500);
RTC_ClearFlag(RTC_FLAG_SEC);
while(RTC_GetFlagStatus(RTC_FLAG_SEC) == RESET);
/* Alarm in 3 second */
RTC_SetAlarm(RTC_GetCounter()+ 60);
/* Wait until last write operation on RTC registers has finished */
RTC_WaitForLastTask();
// RCC_ClearFlag();
if (dingwei==0)
{
PWR_EnterSTOPMode(PWR_Regulator_LowPower, PWR_STOPEntry_WFI);
SYSCLKConfig_STOP();
Delay1(2000);
}
}
}
/*******************************************************************************
* Function Name : PWR_EnterSTOPMode
* Description : Enters STOP mode.
* Input : - PWR_Regulator: specifies the regulator state in STOP mode.
* This parameter can be one of the following values:
* - PWR_Regulator_ON: STOP mode with regulator ON
* - PWR_Regulator_LowPower: STOP mode with
* regulator in low power mode
* - PWR_STOPEntry: specifies if STOP mode in entered with WFI or
* WFE instruction.
* This parameter can be one of the following values:
* - PWR_STOPEntry_WFI: enter STOP mode with WFI instruction
* - PWR_STOPEntry_WFE: enter STOP mode with WFE instruction
* Output : None
* Return : None
*******************************************************************************/
void PWR_EnterSTOPMode(u32 PWR_Regulator, u8 PWR_STOPEntry)
{
u32 tmpreg = 0;
/* Check the parameters */
assert_param(IS_PWR_REGULATOR(PWR_Regulator));
assert_param(IS_PWR_STOP_ENTRY(PWR_STOPEntry));
/* Select the regulator state in STOP mode ---------------------------------*/
tmpreg = PWR->CR;
/* Clear PDDS and LPDS bits */
tmpreg &= CR_DS_Mask;
/* Set LPDS bit according to PWR_Regulator value */
tmpreg |= PWR_Regulator;
/* Store the new value */
PWR->CR = tmpreg;
/* Set SLEEPDEEP bit of Cortex System Control Register */
*(vu32 *) SCB_SysCtrl |= SysCtrl_SLEEPDEEP_Set;
/* Select STOP mode entry --------------------------------------------------*/
if(PWR_STOPEntry == PWR_STOPEntry_WFI)
{
/* Request Wait For Interrupt */
__WFI();
}
else
{
/* Request Wait For Event */
__WFE();
}
}
/*******************************************************************************
* Function Name : RTCAlarm_IRQHandler
* Description : This function handles RTC Alarm interrupt request.
* Input : None
* Output : None
* Return : None
*******************************************************************************/
void RTCAlarm_IRQHandler(void)
{
if(RTC_GetITStatus(RTC_IT_ALR) != RESET)
{
/* Clear EXTI line17 pending bit */
EXTI_ClearITPendingBit(EXTI_Line17);
/* Check if the Wake-Up flag is set */
if(PWR_GetFlagStatus(PWR_FLAG_WU) != RESET)
{
/* Clear Wake Up flag */
PWR_ClearFlag(PWR_FLAG_WU);
}
/* Wait until last write operation on RTC registers has finished */
RTC_WaitForLastTask();
/* Clear RTC Alarm interrupt pending bit */
RTC_ClearITPendingBit(RTC_IT_ALR);
/* Wait until last write operation on RTC registers has finished */
RTC_WaitForLastTask();
USART_ITConfig(USART3,USART_IT_RXNE , ENABLE);
GPIO_SetBits(GPIOB, GPIO_Pin_12); //给GPS供电打开
}
}
|