Beispiel #1
0
/*******************************************************************************
* Function Name  : Alarm_Adjust
* Description    : Adjusts an alarm event to occurs within the current day.
* Input          : None
* Output         : None
* Return         : None
*******************************************************************************/
void Alarm_Adjust(void)
{
  /* Disable the JoyStick interrupts */
  IntExtOnOffConfig(DISABLE);

  while(ReadKey() != NOKEY)
  {
  }
  
  RCC_AHBPeriphClockCmd(RCC_AHBPeriph_FSMC, ENABLE);
  /* Clear the LCD screen */
  LCD_Clear(White);

  LCD_SetDisplayWindow(160, 223, 128, 128);
 
  LCD_NORDisplay(ALARM_ICON);
  RCC_AHBPeriphClockCmd(RCC_AHBPeriph_FSMC, ENABLE);
  /* Disable LCD Window mode */
  LCD_WindowModeDisable();
  
  Alarm_PreAdjust();

  /* Clear the LCD */
  LCD_Clear(White);
  /* Display the menu */
  DisplayMenu();
  /* Enable the JoyStick interrupts */
  IntExtOnOffConfig(ENABLE);  
}
/*******************************************************************************
* Function Name  : EnterSTANDBYMode_RTCAlarm
* Description    : Enters MCU in STANDBY mode. The wake-up from STANDBY mode is 
*                  performed by an RTC Alarm event.
* Input          : None
* Output         : None
* Return         : None
*******************************************************************************/
void EnterSTANDBYMode_RTCAlarm(void)
{
  uint32_t tmp = 0;

  LCD_Clear(White);
  /* Set the LCD Back Color */
  LCD_SetBackColor(Blue);

  /* Set the LCD Text Color */
  LCD_SetTextColor(White);

  /* Disable the JoyStick interrupts */
  IntExtOnOffConfig(DISABLE);
  if(BKP_ReadBackupRegister(BKP_DR1) != 0xA5A5)
  {
    LCD_DisplayStringLine(Line1, "Time and Date are   ");
    LCD_DisplayStringLine(Line2, "not configured,     ");
    LCD_DisplayStringLine(Line3, "please go to the    ");
    LCD_DisplayStringLine(Line4, "calendar menu and   ");
    LCD_DisplayStringLine(Line5, "set the time and    ");
    LCD_DisplayStringLine(Line6, "date parameters.    ");
    LCD_DisplayStringLine(Line7, "Press JoyStick to   ");
    LCD_DisplayStringLine(Line8, "continue...         ");
    while(ReadKey() == NOKEY)
    {
    }
    /* Clear the LCD */
    LCD_Clear(White);
    /* Display the previous menu */
    DisplayMenu();
    /* Enable the JoyStick interrupts */
    IntExtOnOffConfig(ENABLE);
    return;
  }
  
  tmp = RTC_GetCounter();

  /* Save the Alarm value in the Backup register */
  BKP_WriteBackupRegister(BKP_DR6, (tmp & 0x0000FFFF));
  BKP_WriteBackupRegister(BKP_DR7, (tmp >> 16));

  Alarm_PreAdjust();

  LCD_DisplayStringLine(Line7, " MCU in STANDBY Mode");
  LCD_DisplayStringLine(Line8, " Wait For RTC Alarm ");

  /* Request to enter STANDBY mode (Wake Up flag is cleared in PWR_EnterSTANDBYMode function) */
  PWR_EnterSTANDBYMode();
}
/*******************************************************************************
* Function Name  : EnterSTOPMode_RTCAlarm
* Description    : Enters MCU in STOP mode. The wake-up from STOP mode is 
*                  performed by an RTC Alarm.
* Input          : None
* Output         : None
* Return         : None
*******************************************************************************/
void EnterSTOPMode_RTCAlarm(void)
{  
  uint32_t tmp = 0;

  /* Clear the LCD */
  LCD_Clear(White);
  /* Set the LCD Back Color */
  LCD_SetBackColor(Blue);

  /* Set the LCD Text Color */
  LCD_SetTextColor(White);

  /* Disable the JoyStick interrupts */
  IntExtOnOffConfig(DISABLE);

  if(BKP_ReadBackupRegister(BKP_DR1) != 0xA5A5)
  {
    LCD_DisplayStringLine(Line1, "Time and Date are   ");
    LCD_DisplayStringLine(Line2, "not configured,     ");
    LCD_DisplayStringLine(Line3, "please go to the    ");
    LCD_DisplayStringLine(Line4, "calendar menu and   ");
    LCD_DisplayStringLine(Line5, "set the time and    ");
    LCD_DisplayStringLine(Line6, "date parameters.    ");
    LCD_DisplayStringLine(Line7, "Press JoyStick to   ");
    LCD_DisplayStringLine(Line8, "continue...         ");
    while(ReadKey() == NOKEY)
    {
    }
    /* Clear the LCD */
    LCD_Clear(White);
    /* Display the previous menu */
    DisplayMenu();
    /* Enable the JoyStick interrupts */
    IntExtOnOffConfig(ENABLE);
    return;
  }
  tmp = RTC_GetCounter();

  /* Save the Alarm value in the Backup register */
  BKP_WriteBackupRegister(BKP_DR6, (tmp & 0x0000FFFF));
  BKP_WriteBackupRegister(BKP_DR7, (tmp >> 16));
  
  Alarm_PreAdjust();
  LCD_ClearLine(Line8);
  LCD_DisplayStringLine(Line6, "  MCU in STOP Mode  "); 
  LCD_DisplayStringLine(Line7, " Wait For RTC Alarm ");
  
  /* Save the GPIO pins current configuration then put all GPIO pins in Analog Input mode */
  GPIO_SaveConfig();
  
  /* Request to enter STOP mode with regulator in low power */
  PWR_EnterSTOPMode(PWR_Regulator_LowPower, PWR_STOPEntry_WFI);

  /* Restore the GPIO Configurations*/
  GPIO_RestoreConfig();
  
  /* Configures system clock after wake-up from STOP: enable HSE, PLL and select PLL
     as system clock source (HSE and PLL are disabled in STOP mode) */
  SYSCLKConfig_STOP();

  LCD_DisplayStringLine(Line4, "      STOP Mode     ");
  LCD_DisplayStringLine(Line5, "Wake-Up by RTC Alarm");
  LCD_DisplayStringLine(Line6, "Press JoyStick to   ");
  LCD_DisplayStringLine(Line7, "continue...         ");

  while(ReadKey() == NOKEY)
  {
  }

  /* Clear the LCD */
  LCD_Clear(White);
  /* Display the previous menu */
  DisplayMenu();
  /* Enable the JoyStick interrupts */
  IntExtOnOffConfig(ENABLE);
}