Esempio n. 1
0
void test(void)
{
	//Reads data from the specified RTC Backup data Register.
	//入侵检测
if (RTC_ReadBackupRegister(RTC_BKP_DR0) != 0x32F2)
  {
    /* RTC configuration  */
    RTC_Config();
    /* Configure the time&date register */
    RTC_TimeRegulate(); 
  }
else
  {
    /* Enable the PWR clock */
    RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);
    /* Allow access to RTC */
    PWR_BackupAccessCmd(ENABLE);
    /* Wait for RTC APB registers synchronisation */
    RTC_WaitForSynchro();
    /* Clear the RTC Alarm Flag */
    RTC_ClearFlag(RTC_FLAG_ALRAF);
    /* Clear the EXTI Line 17 Pending bit (Connected internally to RTC Alarm) */
    EXTI_ClearITPendingBit(EXTI_Line17);
  }
  while (1);
}
Esempio n. 2
0
/**
  * @brief  Main program.
  * @param  None
  * @retval None
  */
int main(void)
{
  /*!< At this stage the microcontroller clock setting is already configured, 
       this is done through SystemInit() function which is called from startup
       file (startup_stm32f0xx.s) before to branch to application main.
       To reconfigure the default setting of SystemInit() function, refer to
       system_stm32f0xx.c file
     */ 
  /* Configure Systick */
  SysTick_Configuration();
  
  /* Configures the KEY button */
  STM_EVAL_PBInit(BUTTON_KEY,BUTTON_MODE_GPIO);
  
  /* Configure LED3 */
  STM_EVAL_LEDInit(LED3);
        
  while(STM_EVAL_PBGetState(BUTTON_KEY) != RESET);
  
  /* Configure RTC clock source and prescaler */
  RTC_Config();
 
  while(1)
  {}
}
Esempio n. 3
0
/**
  * @brief  Main program
  * @param  None
  * @retval None
  */
int main(void)
{
  /* STM32F0xx HAL library initialization:
       - Configure the Flash prefetch
       - Systick timer is configured by default as source of time base, but user 
         can eventually implement his proper time base source (a general purpose 
         timer for example or other time source), keeping in mind that Time base 
         duration should be kept 1ms since PPP_TIMEOUT_VALUEs are defined and 
         handled in milliseconds basis.
       - Low Level Initialization
     */
  HAL_Init();

  /* Configure LED1, LED2 */
  BSP_LED_Init(LED1);
  BSP_LED_Init(LED2);

  /* Configure the system clock to 48 MHz */
  SystemClock_Config();

  /* Enable Power Clock */
  __PWR_CLK_ENABLE();
  
  /* Check if the system was resumed from StandBy mode */
  if (__HAL_PWR_GET_FLAG(PWR_FLAG_SB) != RESET)
  {
    /* Wait that user release the Tamper push-button */
    BSP_PB_Init(BUTTON_TAMPER, BUTTON_MODE_GPIO);
    while(BSP_PB_GetState(BUTTON_TAMPER) == GPIO_PIN_RESET){}
  }

  /* Initialize the Tamper push-button to generate external interrupts */
  BSP_PB_Init(BUTTON_TAMPER, BUTTON_MODE_EXTI);

  /* RTC configuration */
  RTC_Config();

  /* Turn on LED1 */
  BSP_LED_On(LED1);

  /*The Following Wakeup sequence is highly recommended prior to each Standby mode entry
    mainly  when using more than one wakeup source this is to not miss any wakeup event.
     - Disable all used wakeup sources,
     - Clear all related wakeup flags, 
     - Re-enable all used wakeup sources,
     - Enter the Standby mode.
  */
  /*Disable all used wakeup sources: Pin1(PA.0)*/
  HAL_PWR_DisableWakeUpPin(PWR_WAKEUP_PIN1);
  
  /*Clear all related wakeup flags*/
  __HAL_PWR_CLEAR_FLAG(PWR_FLAG_WU);
  
  /*Re-enable all used wakeup sources: Pin1(PA.0)*/
  HAL_PWR_EnableWakeUpPin(PWR_WAKEUP_PIN1);

  while (1)
  {
  }
}
Esempio n. 4
0
/**
  * @brief  Main program
  * @param  None
  * @retval None
  */
int main(void)
{
  /*!< At this stage the microcontroller clock setting is already configured, 
       this is done through SystemInit() function which is called from startup
       files (startup_stm32f40_41xxx.s/startup_stm32f427_437xx.s/startup_stm32f429_439xx.s)
       before to branch to application main. 
       To reconfigure the default setting of SystemInit() function, refer to
       system_stm32f4xx.c file
     */     

  /* Initialize LEDs mounted on EVAL board */
  STM_EVAL_LEDInit(LED1);
  STM_EVAL_LEDInit(LED2);
  
  /* Initialize Key Button mounted on EVAL board */
  STM_EVAL_PBInit(BUTTON_KEY, BUTTON_MODE_EXTI);

  /* RTC configuration */
  RTC_Config();

  /* Turn on LED1 */
  STM_EVAL_LEDOn(LED1);

  /* Enable WKUP pin  */
  PWR_WakeUpPinCmd(ENABLE);

  /* Configure the SysTick to generate an interrupt each 250 ms */
  SysTick_Configuration();

  while (1)
  {
  }
}
Esempio n. 5
0
/**
  * @brief  Main program.
  * @param  None
  * @retval None
  */
int main(void)
{
    /*!< At this stage the microcontroller clock setting is already configured,
         this is done through SystemInit() function which is called from startup
         file (startup_stm32f0xx.s) before to branch to application main.
         To reconfigure the default setting of SystemInit() function, refer to
         system_stm32f0xx.c file
       */
    /* Configure LED3 */
    STM_EVAL_LEDInit(LED3);

    /* Configure Systick */
    SysTick_Configuration();

    /* Turn ON LED3 */
    STM_EVAL_LEDOn(LED3);

    /* Configures User button */
    STM_EVAL_PBInit(BUTTON_USER,BUTTON_MODE_GPIO);

    /* Configure RTC clock source and prescaler */
    RTC_Config();

    /* Wait till User button is pressed */
    while(STM_EVAL_PBGetState(BUTTON_USER) == RESET);

    /* Enter STANDBY mode, RTC Alarm within 3 second or an external RESET will
     wake-up the system from STANDBY */
    EnterSTANDBYMode();

    while(1)
    {}
}
Esempio n. 6
0
void RTC_to_default_config(void)
{
    //enable clk for PWR & allow access to RTC
    /* Enable the PWR clock */
    RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);

    /* Allow access to RTC */
    PWR_RTCAccessCmd(ENABLE);

    /* RTC Configuration -------------------------------------------------------*/
    RTC_Config();
    RTC_DateStructure.RTC_Month = RTC_Month_May;
    RTC_DateStructure.RTC_Date = 1;
    RTC_DateStructure.RTC_Year = 13;
    RTC_DateStructure.RTC_WeekDay = RTC_Weekday_Wednesday;


    RTC_TimeStructure.RTC_H12     = RTC_H12_AM;
    RTC_TimeStructure.RTC_Hours = 12;
    RTC_TimeStructure.RTC_Minutes = 00;
    RTC_TimeStructure.RTC_Seconds = 00;


    RTC_SetTime(RTC_Format_BIN, &RTC_TimeStructure);
    //RTC_SetDate(RTC_Format_BIN,&RTC_DateStructure);

    //disable access to RTC & disable clk to PWR
    PWR_RTCAccessCmd(DISABLE);
    //RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, DISABLE);
}
Esempio n. 7
0
File: main.c Progetto: shjere/common
/**
  * @brief  Main program.
  * @param  None
  * @retval None
  */
int main(void)
{
  /* STM32L0xx HAL library initialization:
       - Configure the Flash prefetch, Flash preread and Buffer caches
       - Systick timer is configured by default as source of time base, but user 
             can eventually implement his proper time base source (a general purpose 
             timer for example or other time source), keeping in mind that Time base 
             duration should be kept 1ms since PPP_TIMEOUT_VALUEs are defined and 
             handled in milliseconds basis.
       - Low Level Initialization
     */
  HAL_Init();
  
  /*******************************************************************************
  *                          Common Configuration Routines                       *
  *******************************************************************************/  
  /* Configure LED2 */
  BSP_LED_Init(LED2);

  /* Configure the system clock to 32 Mhz */
  SystemClock_Config();

  /* Configure Button Key */
  BSP_PB_Init(BUTTON_KEY, BUTTON_MODE_GPIO);

  /* RTC Configuration -------------------------------------------------------*/
  RTC_Config();

  /* Wait Until KEY BUTTON is pressed */
  while(BSP_PB_GetState(BUTTON_KEY) != RESET)
  {
  }
  while(BSP_PB_GetState(BUTTON_KEY) != SET)
  {
  }
  
  /* Get the LSI frequency:  TIM21 is used to measure the LSI frequency */
  uwLsiFreq = GetLSIFrequency();
  
  /* Update the Calendar Configuration with the LSI exact value */
  RtcHandle.Init.HourFormat = RTC_HOURFORMAT_24;
  RtcHandle.Init.AsynchPrediv = 0x7F;
  RtcHandle.Init.SynchPrediv = (uwLsiFreq/128) - 1;
  RtcHandle.Init.OutPut = RTC_OUTPUT_DISABLE;
  RtcHandle.Init.OutPutPolarity = RTC_OUTPUT_POLARITY_HIGH;
  RtcHandle.Init.OutPutType = RTC_OUTPUT_TYPE_OPENDRAIN;
  
  if(HAL_RTC_Init(&RtcHandle) != HAL_OK)
  {
    /* Initialization Error */
    Error_Handler();
  }

  /* Infinite loop */
  while (1)
  {
  }
}
Esempio n. 8
0
/**
  * @brief  Main program.
  * @param  None
  * @retval None
  */
int main(void)
{
  /*!< At this stage the microcontroller clock setting is already configured, 
       this is done through SystemInit() function which is called from startup
       files (startup_stm32f40_41xxx.s/startup_stm32f427_437xx.s/startup_stm32f429_439xx.s)
       before to branch to application main.
     */  
  
  /* Initialize the LCD */
  LCD_Init(); 
  
  /* Clear the LCD */ 
  LCD_Clear(White);

  /* Set the LCD Back Color */
  LCD_SetBackColor(Blue);
  
  /* Set the LCD Text Color */
  LCD_SetTextColor(White);
   
  /* Displays MESSAGE1 on line 0 */
  LCD_DisplayStringLine(LINE(0), (uint8_t *)MESSAGE1);

  /* RTC configuration */
  RTC_Config();
  
  /* Set the LCD Text Color */
  LCD_SetTextColor(Red);
  
  /* Displays a rectangle on the LCD */
  LCD_DrawRect(80, 290, 25, 240 );
  
  /* Configure the external interrupt "KEY", "WAKEUP" and "TAMPER" buttons */
  STM_EVAL_PBInit(BUTTON_KEY, BUTTON_MODE_EXTI);
  STM_EVAL_PBInit(BUTTON_WAKEUP, BUTTON_MODE_EXTI);
  STM_EVAL_PBInit(BUTTON_TAMPER, BUTTON_MODE_EXTI);  
     
  /* Configure RTC alarm A register to generate 8 interrupts per 1 Second */
  RTC_AlarmConfig();
  
  /* set LCD Font */
  LCD_SetFont(&Font12x12);

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

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

  /* Displays MESSAGE2 and MESSAGE3 on the LCD */
  LCD_DisplayStringLine(LINE(18), (uint8_t *)MESSAGE2);  
  LCD_DisplayStringLine(LINE(19), (uint8_t *)MESSAGE3);  

  /* Infinite loop */
  while (1)
  {}
}
Esempio n. 9
0
/*
*********************************************************************************************************
*	函 数 名: bsp_InitRTC
*	功能说明: 初始化RTC
*	形    参:无
*	返 回 值: 无		        
*********************************************************************************************************
*/
void bsp_InitRTC(void)
{
	//RTC_DeInit();
	RTC_Config();   /* 配置RTC模块 */
	
if (OBCBootInfo.BootCnt == 0)   /* 第一次开机 */
{  
	/* 检测上电复位标志是否设置 */
	if (RCC_GetFlagStatus(RCC_FLAG_PORRST) != RESET)
	{
		/* 发生上电复位 */
		OBCBootInfo.BootPORRSTCnt++;
	}
}

else  /* 第N次开机 */
{
	/* 检测上电复位标志是否设置 */
	if (RCC_GetFlagStatus(RCC_FLAG_PORRST) != RESET)
	{
		/* 发生上电复位 */
		OBCBootInfo.BootPORRSTCnt++;
	}
	
	/* 检测引脚复位标志是否设置 */
	else if (RCC_GetFlagStatus(RCC_FLAG_PINRST) != RESET)
	{
		/* 发生引脚复位 */
		OBCBootInfo.BootPINRSTCnt++;
	}
	else if (RCC_GetFlagStatus(RCC_FLAG_SFTRST) != RESET)
	{
		OBCBootInfo.BootSFTRSTCnt++;
	}
	else if (RCC_GetFlagStatus(RCC_FLAG_IWDGRST) != RESET)
	{
		/* 发生独立看门狗复位 */
    OBCBootInfo.BootIWDGRSTCnt++;
	}
	else if (RCC_GetFlagStatus(RCC_FLAG_WWDGRST) != RESET)
	{
		/* 发生窗口看门狗复位 */
		OBCBootInfo.BootWWDGRSTCnt++;
	}
	else if (RCC_GetFlagStatus(RCC_FLAG_LPWRRST) != RESET)
	{
		/* 发生低电压复位 */
    OBCBootInfo.BootLPWRRSTCnt++;
	}
}

}
Esempio n. 10
0
/**
  * @brief  Main program
  * @param  None
  * @retval None
  */
int main(void)
{
  /* STM32F107xC HAL library initialization:
       - Configure the Flash prefetch
       - Systick timer is configured by default as source of time base, but user 
         can eventually implement his proper time base source (a general purpose 
         timer for example or other time source), keeping in mind that Time base 
         duration should be kept 1ms since PPP_TIMEOUT_VALUEs are defined and 
         handled in milliseconds basis.
       - Set NVIC Group Priority to 4
       - Low Level Initialization
     */
  HAL_Init();

  /* Configure the system clock to 72 MHz */
  SystemClock_Config();

  /* Configure LED1 */
  BSP_LED_Init(LED1);
  BSP_LED_Init(LED_RED);

  /* Configure Button Key */
  BSP_PB_Init(BUTTON_KEY, BUTTON_MODE_GPIO);

  /* RTC Configuration -------------------------------------------------------*/
  RTC_Config();

  /* Wait Until KEY BUTTON is pressed */
  while(BSP_PB_GetState(BUTTON_KEY) != RESET)
  {
  }
  while(BSP_PB_GetState(BUTTON_KEY) != SET)
  {
  }
  
  /* Get the LSI frequency:  TIM5 is used to measure the LSI frequency */
  uwLsiFreq = GetLSIFrequency();
  
  /* Update the Calendar Configuration with the LSI exact value */
  RtcHandle.Init.AsynchPrediv = (uwLsiFreq - 1);
  
  if(HAL_RTC_Init(&RtcHandle) != HAL_OK)
  {
    /* Initialization Error */
    Error_Handler();
  }

  /* Infinite loop */
  while (1)
  {
  }
}
Esempio n. 11
0
/**
* @brief  Main program
* @param  None
* @retval None
*/
int main(void)
{    
  /* STM32F4xx HAL library initialization:
       - Configure the Flash prefetch, instruction and Data caches
       - Configure the Systick to generate an interrupt each 1 msec
       - Set NVIC Group Priority to 4
       - Global MSP (MCU Support Package) initialization
     */
  HAL_Init();  

  /* Configure the system clock to 180 MHz */
  SystemClock_Config();
  
  /* Configure LED1 and LED3 */
  BSP_LED_Init(LED1);
  BSP_LED_Init(LED3);

  /* Configure Key Button */
  BSP_PB_Init(BUTTON_TAMPER, BUTTON_MODE_EXTI);
  
  /* Configure Joystick using MFX in IT mode in order to wakeup system after standby */
  BSP_JOY_Init(JOY_MODE_EXTI);

  /* RTC configuration */
  RTC_Config();
  
  /* Turn on LED1 */
  BSP_LED_On(LED1);

  /* Enable WKUP pin */
  HAL_PWR_EnableWakeUpPin(PWR_WAKEUP_PIN1);

  /* Infinite loop */
  while (1)
  {
    if (AuthorizeToggle)
    {
      /* Toggle LED1 */
      BSP_LED_Toggle(LED1);
      AuthorizeToggle = 0;
    }
    if (MfxExtiReceived)
    {
      /* Clear MFX IT */
      BSP_IO_ITClear();
      MfxExtiReceived = 0;
    }
  }
}
Esempio n. 12
0
/**
  * @brief  Main program
  * @param  None
  * @retval None
  */
int main(void)
{
  /* Enable the CPU Cache */
  CPU_CACHE_Enable();
  
  /* STM32F7xx HAL library initialization:
       - Configure the Flash ART accelerator on ITCM interface
       - Systick timer is configured by default as source of time base, but user 
         can eventually implement his proper time base source (a general purpose 
         timer for example or other time source), keeping in mind that Time base 
         duration should be kept 1ms since PPP_TIMEOUT_VALUEs are defined and 
         handled in milliseconds basis.
       - Set NVIC Group Priority to 4
       - Low Level Initialization
     */
  HAL_Init();

  /* Configure the system clock to 216 MHz */
  SystemClock_Config();
  
  /* Configure LED1, LED3 */
  BSP_LED_Init(LED1);
  BSP_LED_Init(LED3);

  /* Enable Power Clock */
  __HAL_RCC_PWR_CLK_ENABLE();
  
  /* Check if the system was resumed from StandBy mode */
  if (__HAL_PWR_GET_FLAG(PWR_FLAG_SB) != RESET)
  {
    /* Wait that user release the Tamper push-button */
    BSP_PB_Init(BUTTON_TAMPER, BUTTON_MODE_GPIO);
    while(BSP_PB_GetState(BUTTON_TAMPER) == GPIO_PIN_SET){}
  }

  /* Initialize the Tamper push-button to generate external interrupts */
  BSP_PB_Init(BUTTON_TAMPER, BUTTON_MODE_EXTI);

  /* RTC configuration */
  RTC_Config();

  /* Turn on LED1 */
  BSP_LED_On(LED1);

  while (1)
  {
  }
}
Esempio n. 13
0
/**
  * @brief   Main program
  * @param  None
  * @retval None
  */
int main(void)
{
  NVIC_InitTypeDef NVIC_InitStructure;
  /*!< At this stage the microcontroller clock setting is already configured,
       this is done through SystemInit() function which is called from startup
       file (startup_stm32f4xx.s) before to branch to application main.
       To reconfigure the default setting of SystemInit() function, refer to
       system_stm32f4xx.c file
     */

  /* Initialize LEDs and Key Button mounted on STM32F4-Discovery board */
  STM_EVAL_LEDInit(LED4);
  STM_EVAL_LEDInit(LED3);

  /* Configure Button EXTI line */
  EXTI_InitStructure.EXTI_Line = EXTI_Line1;
  EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
  EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising_Falling;
  EXTI_InitStructure.EXTI_LineCmd = ENABLE;
  EXTI_Init(&EXTI_InitStructure);

  /* Enable and set Button EXTI Interrupt to the lowest priority */
  NVIC_InitStructure.NVIC_IRQChannel = EXTI1_IRQn;
  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x0F;
  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x0F;
  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;

  NVIC_Init(&NVIC_InitStructure);

  /* RTC configuration */
  RTC_Config();

  /* Turn on LED4 */
  STM_EVAL_LEDOn(LED4);

  /* Enable WKUP pin  */
  PWR_WakeUpPinCmd(ENABLE);

  /* Configure the SysTick to generate an interrupt each 250 ms */
  SysTick_Configuration();

  while (1)
  {
  }
}
Esempio n. 14
0
File: main.c Progetto: agb861/STM32F
/**
  * @brief  Main program
  * @param  None
  * @retval None
  */
int main(void)
{
  /*!< At this stage the microcontroller clock setting is already configured, 
       this is done through SystemInit() function which is called from startup
       file (startup_stm32f2xx.s) before to branch to application main.
       To reconfigure the default setting of SystemInit() function, refer to
       system_stm32f2xx.c file
     */     
       
  /* Configure the SysTick to generate an interrupt each 250 ms */
  SysTick_Configuration();

  /* Initialize LEDs and Key Button mounted on STM322xG-EVAL board */
  STM_EVAL_LEDInit(LED1);
  STM_EVAL_LEDInit(LED2);
  STM_EVAL_LEDInit(LED4);

  /* Key button (EXTI_Line15) will be used to wakeup ths system from STOP mode */
  STM_EVAL_PBInit(BUTTON_KEY, BUTTON_MODE_EXTI);

  /* RTC configuration */
  RTC_Config();

  while (1)
  {
    /* Insert 5 second delay */
    Delay(20);

    /* Turn OFF LED2 */
    STM_EVAL_LEDOff(LED2);

    /* Enable Wakeup Counter */
    RTC_WakeUpCmd(ENABLE);

    /* Enter Stop Mode */
    PWR_EnterSTOPMode(PWR_Regulator_LowPower, PWR_STOPEntry_WFI);
    
    /* Disable Wakeup Counter */
    RTC_WakeUpCmd(DISABLE);

    /* 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();
  }
}
Esempio n. 15
0
/**
  * @brief  stm32cube_hal_init()
  * @param  None
  * @retval None
  */
void stm32cube_hal_init()
{
    HAL_Init();
    /* Configure the system clock */
    SystemClock_Config();

    HAL_EnableDBGStopMode();
    
    MX_GPIO_Init();
    USARTConfig();
    HAL_Spirit1_Init();
    SPIRIT1_Init();
    
   /* Initialize RTC */
   
   RTC_Config();
   RTC_TimeStampConfig();
}
Esempio n. 16
0
void RTC_Time_Init(void)
{
  if (RTC_ReadBackupRegister(RTC_BKP_DR0) != 0x32F2)
  {
    /* RTC configuration  */
    RTC_Config();

    /* Configure the RTC data register and RTC prescaler */
    RTC_InitStructure.RTC_AsynchPrediv = AsynchPrediv;
    RTC_InitStructure.RTC_SynchPrediv = SynchPrediv;
    RTC_InitStructure.RTC_HourFormat = RTC_HourFormat_24;
   
    /* Check on RTC init */
    if (RTC_Init(&RTC_InitStructure) == ERROR)
    {
      MessageBox_Show("Prescaler Config failed", "RTC Error", true, false);
    }
    /* Configure the time register */
    RTC_TimeRegulate(0,0,0); 
  }
  else
  {
    /* Check if the Power On Reset flag is set */
    if (RCC_GetFlagStatus(RCC_FLAG_PORRST) != RESET)
    {
    }
    /* Check if the Pin Reset flag is set */
    else if (RCC_GetFlagStatus(RCC_FLAG_PINRST) != RESET)
    {
    }
    
    /* Enable the PWR clock */
    RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);

    /* Allow access to RTC */
    PWR_BackupAccessCmd(ENABLE);

    /* Wait for RTC APB registers synchronisation */
    RTC_WaitForSynchro();

    /* Clear the RTC Alarm Flag */
    RTC_ClearFlag(RTC_FLAG_ALRAF);
  }	
}
Esempio n. 17
0
/**
* @brief  Main program
* @param  None
* @retval None
*/
int main(void)
{    
   /* STM32F4xx HAL library initialization:
       - Configure the Flash prefetch, instruction and Data caches
       - Configure the Systick to generate an interrupt each 1 msec
       - Set NVIC Group Priority to 4
       - Global MSP (MCU Support Package) initialization
     */
   HAL_Init();

  /* Configure LED1, LED2 */
  BSP_LED_Init(LED1);
  BSP_LED_Init(LED2);

  /* Configure the system clock to 168 MHz */
  SystemClock_Config();

  /* Enable Power Clock */
  __HAL_RCC_PWR_CLK_ENABLE();

  /* Check and Clear the Wakeup flag */
  if (__HAL_PWR_GET_FLAG(PWR_FLAG_WU) != RESET)
  {
    __HAL_PWR_CLEAR_FLAG(PWR_FLAG_WU);
  }

  /* Initialize the Key push-button to generate external interrupts */
  BSP_PB_Init(BUTTON_KEY, BUTTON_MODE_EXTI);

  /* RTC configuration */
  RTC_Config();

  /* Turn on LED1 */
  BSP_LED_On(LED1);

  /* Enable WakeUp Pin PWR_WAKEUP_PIN1 connected to PA.00 */
  HAL_PWR_EnableWakeUpPin(PWR_WAKEUP_PIN1);

  while (1)
  {
  }
}
Esempio n. 18
0
/**
  * @brief   Main program
  * @param  None
  * @retval None
  */
int main(void)
{
  /*!< At this stage the microcontroller clock setting is already configured, 
       this is done through SystemInit() function which is called from startup
       file (startup_stm32f10x_md.s) before to branch to application main.
       To reconfigure the default setting of SystemInit() function, refer to
       system_stm32f10x.c file
     */ 

  /* Initialize LEDs mounted on STM32NUCLEO board --------------------------*/
  STM_EVAL_LEDInit(LED2);
    
  /* Configure RTC */
  RTC_Config();
  
  while (1)
  {
    /* Show Time */
    Show_Time(RTC_GetCounter());
  }
}
Esempio n. 19
0
/*****************************************************************************
 * FUNCTION
 *  uem_init_hardware_data
 * DESCRIPTION
 *
 * PARAMETERS
 *  void
 * RETURNS
 *
 *****************************************************************************/
kal_bool uem_init_hardware_data(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    kal_bool ret_val = KAL_TRUE;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    /* when the last block EF nvram is reading ready, we will start to init HW environment */
    /* The audio init responsbility is change to MMI */
    /* initial RTC: Clock for one minute period, Alarm for no change */
    RTC_Config(uem_rtc_alarm_format_convert(DEVICE_AL_EN_NoChange), uem_rtc_clock_format_convert(DEVICE_TC_EN_ChkM));

    /* initial audio */
    l4cuem_set_mute_req(AUDIO_DEVICE_SPEAKER, KAL_FALSE);
    l4cuem_set_mute_req(AUDIO_DEVICE_MICROPHONE, KAL_FALSE);

#ifdef __MTK_TARGET__
    /* Initial ADC valur  */
    if (g_uem_cntx_p->adc_sche_id == 0)
    {
        g_uem_cntx_p->adc_sche_id = adc_sche_create_object(
                                        MOD_UEM,
                                        ADC_VBAT,
                                        ADC_BOOTUP_EVAL_PERIOD,
                                        (kal_uint8) ADC_BOOTUP_EVAL_COUNT,
                                        KAL_TRUE);
        /* send to the BMT task to register the callback message */
        uem_send_msg_to_bmt(MSG_ID_BMT_ADC_ADD_ITEM_REQ, g_uem_cntx_p->adc_sche_id);
    }

    /* Initial Keypad longpress/repeattime value */
    Kbd_SetLongPressTime(KPD_LONGPRESS_PERIOD);   /* ticks, in unit 10ms */
    Kbd_SetRepeatTime(KPD_REPEAT_PERIOD);         /* ticks, in unit 10ms */
#endif /* __MTK_TARGET__ */

    return ret_val;
}
Esempio n. 20
0
/**
  * @brief  Main program
  * @param  None
  * @retval None
  */
int main(void)
{
  /*!< At this stage the microcontroller clock setting is already configured, 
       this is done through SystemInit() function which is called from startup
       files (startup_stm32f40_41xxx.s/startup_stm32f427_437xx.s)
       before to branch to application main.
     */     
   
  /* Initialize LEDs mounted on EVAL board */
  STM_EVAL_LEDInit(LED1);
  STM_EVAL_LEDInit(LED2);
  
  /* Initialize Tamper Button mounted on EVAL board */
  STM_EVAL_PBInit(BUTTON_TAMPER, BUTTON_MODE_GPIO);
  
  /* RTC Configuration */
  RTC_Config();

  /* Wait Until BUTTON TAMPER is pressed */
  while(STM_EVAL_PBGetState(BUTTON_TAMPER) != RESET)
  {
  }
  
  /* Get the LSI frequency:  TIM5 is used to measure the LSI frequency */
  uwLsiFreq = GetLSIFrequency();

  /* Turn on LED2 */
  STM_EVAL_LEDOn(LED2);

  /* Calendar Configuration */
  /* ck_spre(1Hz) = RTCCLK(LSI) /(AsynchPrediv + 1)*(SynchPrediv + 1)*/
  RTC_InitStructure.RTC_AsynchPrediv = 0x7F;
  RTC_InitStructure.RTC_SynchPrediv	= (uwLsiFreq/128) - 1;
  RTC_InitStructure.RTC_HourFormat = RTC_HourFormat_24;
  RTC_Init(&RTC_InitStructure);

  while (1)
  {
  }
}
Esempio n. 21
0
/**
  * @brief  Main program.
  * @param  None
  * @retval None
  */
int main(void)
{
  /*!< At this stage the microcontroller clock setting is already configured, 
       this is done through SystemInit() function which is called from startup
       file (startup_stm32f30x.s) before to branch to application main.
       To reconfigure the default setting of SystemInit() function, refer to
       system_stm32f30x.c file
     */

 /* Initialize LEDs mounted on STM32303C-EVAL board --------------------------*/
  STM_EVAL_LEDInit(LED1);
  STM_EVAL_LEDInit(LED2);
  STM_EVAL_PBInit(BUTTON_KEY, BUTTON_MODE_GPIO);
  
  /* RTC Configuration -------------------------------------------------------*/
  RTC_Config();

  /* Wait Until KEY BUTTON is pressed */
  while(STM_EVAL_PBGetState(BUTTON_KEY) != RESET)
  {
  }
  
  /* Get the LSI frequency:  TIM16 is used to measure the LSI frequency */
  LsiFreq = GetLSIFrequency();

  /* Turn on LED2 */
  STM_EVAL_LEDOn(LED2);

  /* Calendar Configuration */
  RTC_InitStructure.RTC_AsynchPrediv = 88;
  RTC_InitStructure.RTC_SynchPrediv	=  (LsiFreq/89) - 1;
  RTC_InitStructure.RTC_HourFormat = RTC_HourFormat_24;
  RTC_Init(&RTC_InitStructure);

  /* Infinite loop */
  while (1)
  {
  }
}
Esempio n. 22
0
/**
  * @brief  Configure the Lowpower application 
  * @param  None.
  * @note   run and display information about the lowpower feature.  
  * @retval None.
  */
KMODULE_RETURN _LowPowerDemoConfig(void)
{

  /* Enable Clock Security System(CSS) */
  HAL_RCC_EnableCSS();
  
  /* Configure RTC */
  RTC_Config();

  /*#### Disable all used wakeup sources ####*/
  HAL_RTC_DeactivateAlarm(&RtcHandle, RTC_ALARM_A);
  /* Disable all previous wake up interrupt */
  HAL_PWR_DisableWakeUpPin(PWR_WAKEUP_PIN1);

  /*#### Clear all related wakeup flags ####*/
  /* Clear the Alarm interrupt pending bit */
  __HAL_RTC_ALARM_CLEAR_FLAG(&RtcHandle,RTC_FLAG_ALRAF);
  /* Clear PWR wake up Flag */
  __HAL_PWR_CLEAR_FLAG(PWR_FLAG_WU);

    return KMODULE_OK;
}
Esempio n. 23
0
void RTC_to_default_state(void)
{

	/* RTC Configuration -------------------------------------------------------*/
	RTC_Config();

	  /*1 seconds delay*/
  	//DelayResolution100us(10000);
	/* Get the LSI frequency:  TIM5 is used to measure the LSI frequency */
	LsiFreq = GetLSIFrequency();

	/* Turn on LED2 */
	//STM_EVAL_LEDOn(LED2);

	/* Calendar Configuration */
	//LsiFreq = 35307
	RTC_InitStructure.RTC_AsynchPrediv = 0x7F;
	RTC_InitStructure.RTC_SynchPrediv	=  275;//(LsiFreq/128) - 1;
	//276*128=35328
	//160*220=35200
	//130*271=35300
	RTC_InitStructure.RTC_HourFormat = RTC_HourFormat_24;
	RTC_Init(&RTC_InitStructure);

	RTC_DateStructure.RTC_Month = RTC_Month_March;
	RTC_DateStructure.RTC_Date = 28;
	RTC_DateStructure.RTC_Year = 13;
	RTC_DateStructure.RTC_WeekDay = RTC_Weekday_Thursday;


	RTC_TimeStructure.RTC_H12     = RTC_H12_AM;
	RTC_TimeStructure.RTC_Hours = 16;
	RTC_TimeStructure.RTC_Minutes = 30;
	RTC_TimeStructure.RTC_Seconds = 00;

	//RTC_SetTime(RTC_Format_BIN, &RTC_TimeStructure);
	//RTC_SetDate(RTC_Format_BIN,&RTC_DateStructure);

}
Esempio n. 24
0
/**
  * @brief  Main program
  * @param  None
  * @retval None
  */
int main(void)
{
  /*!< At this stage the microcontroller clock setting is already configured, 
       this is done through SystemInit() function which is called from startup
       files (startup_stm32f40xx.s/startup_stm32f427x.s) before to branch to 
       application main. 
       To reconfigure the default setting of SystemInit() function, refer to
       system_stm32f4xx.c file
     */

  /* Initialize Leds mounted on EVAL board */
  STM_EVAL_LEDInit(LED1);
  STM_EVAL_LEDInit(LED2);
  STM_EVAL_LEDInit(LED3);
  STM_EVAL_LEDInit(LED4);
  
  /* RTC configuration */
  RTC_Config();

  /* Write To RTC Backup Data registers */
  WriteToRTC_BKP_DR(0xA53C);

  /* Check if the written data are correct */
  if(CheckRTC_BKP_DR(0xA53C) == 0)
  {
    /* Turn on LED1 */
    STM_EVAL_LEDOn(LED1);
  }
  else
  {
    /* Turn on LED3 */
    STM_EVAL_LEDOn(LED3);
  }

  while (1)
  {
  }
}
Esempio n. 25
0
//获取时间
char* get_time(void)
{  
	char time[100]={'\0'};
	RTC_TimeTypeDef   	RTC_GetTimeStructure;
	RTC_DateTypeDef 	RTC_GetDateStructure;
	if (RTC_ReadBackupRegister(RTC_BKP_DR0) != 0x32F1)//假如修改了,则再次进行配置
		{
			RTC_Config(extrnal);
			set_time(0x15,0x12,0x28,0x14,0x50,0x01,0x01,RTC_H12_PM);
			//return "fail"
		}
	else
		{//没有修改,则直接继续
			RTC_GetTime(RTC_Format_BIN, &RTC_GetTimeStructure);
			RTC_GetDate(RTC_Format_BIN, &RTC_GetDateStructure);
			//2015-11-10-10:18:33
			sprintf(time,"20%d-%d-%d-%d:%d:%d",\
			RTC_GetDateStructure.RTC_Year,RTC_GetDateStructure.RTC_Month,\
			RTC_GetDateStructure.RTC_Date,RTC_GetTimeStructure.RTC_Hours,\
			RTC_GetTimeStructure.RTC_Minutes,RTC_GetTimeStructure.RTC_Seconds);
		}
	return time;
}
Esempio n. 26
0
/**
  * @brief  Main program.
  * @param  None
  * @retval None
  */
void RTC_Tamper_Example(void)
{
  /*!< At this stage the microcontroller clock setting is already configured, 
       this is done through SystemInit() function which is called from startup
       file (startup_stm32f30x.s) before to branch to application main.
       To reconfigure the default setting of SystemInit() function, refer to
       system_stm32f30x.c file
     */

  /* Initialize Leds mounted on STM32303C-EVAL board */
  STM_EVAL_LEDInit(LED1);
  STM_EVAL_LEDInit(LED2);
  STM_EVAL_LEDInit(LED3);
  STM_EVAL_LEDInit(LED4);

  /* RTC configuration */
  RTC_Config();

  /* Write To RTC Backup Data registers */
  RTC_BackUpDRWrite(0xA53C);

  /* Check if the written data are correct */
  if(RTC_BackUpDRCheck(0xA53C) == 0x00)
  {
    /* Turn on LED1 */
    STM_EVAL_LEDOn(LED1);
  }
  else
  {
    /* Turn on LED3 */
    STM_EVAL_LEDOn(LED3);
  }
  /* Infinite loop */
  while (1)
  {
  }
}
Esempio n. 27
0
/**
  * @brief  Main program.
  * @param  None
  * @retval None
  */
int main(void)
{
  /*!< At this stage the microcontroller clock setting is already configured, 
       this is done through SystemInit() function which is called from startup
       file (startup_stm32f0xx.s) before to branch to application main.
       To reconfigure the default setting of SystemInit() function, refer to
       system_stm32f0xx.c file
     */ 

  RTC_TimeTypeDef  RTC_TimeStruct;
  
  /* Initialize the LCD */
  STM320518_LCD_Init();      
    
  /* Clear the LCD */
  LCD_Clear(LCD_COLOR_WHITE);
  
  /* Set the LCD Back Color */
  LCD_SetBackColor(Blue);
  
  /* Set the LCD Text Color */
  LCD_SetTextColor(White);
  
  /* Displays MESSAGE1 on line 1 */
  LCD_DisplayStringLine(LINE(0), (uint8_t *)MESSAGE1);
  
  /* Set the LCD Text Color */
  LCD_SetTextColor(Red);
  
  /* Set the LCD Back Color */
  LCD_SetBackColor(Red);
  LCD_DrawFullRect(31, 292,264,34);
  
  /* Set the LCD Back Color */
  LCD_SetBackColor(White);
  LCD_DrawFullRect(33, 290 ,260,30);
  
  /* Configure the external interrupt "RIGHT" and "LEFT" buttons */
  STM_EVAL_PBInit(BUTTON_RIGHT,BUTTON_MODE_EXTI);
  STM_EVAL_PBInit(BUTTON_LEFT,BUTTON_MODE_EXTI);
  
  /* Configure the RTC peripheral by selecting the clock source.*/
  RTC_Config();
  
  /* Configure the RTC tamper register : To Clear all the Backup data register */
  RTC_TamperConfig();
  
  /* Set the LCD Text, Back Colors and Text size */
  LCD_SetTextColor(Black); 
  LCD_SetBackColor(Cyan);
  LCD_SetFont(&Font12x12);
  
  LCD_DisplayStringLine(LINE(18), (uint8_t *)MESSAGE2);
  
  /* Set the LCD Back Color */
  LCD_SetBackColor(Blue);
  LCD_SetTextColor(White);
  
  LCD_DisplayStringLine(LINE(19), (uint8_t *)MESSAGE3);
  
  /* Set text size */
  LCD_SetFont(&Font16x24);
  
  /* Set the LCD Text Color */
  LCD_SetTextColor(Blue);
  
  /* Initialize time Stucture */
  RTC_TimeStructInit(&RTC_TimeStruct); 

  /* Infinite loop */
  while (1)
  {
    /* Set the LCD Back Color and text size */
    LCD_SetFont(&Font16x24);
    LCD_SetBackColor(White);
    
    /* Check on the event 'start' */
    if(StartEvent != 0x0)
    {  
      /* Get the RTC sub second fraction */
      SecondFraction = (((256 - (uint32_t)RTC_GetSubSecond()) * 1000) / 256);
      
      /* Get the Curent time */
      RTC_GetTime(RTC_Format_BIN, &RTC_TimeStruct);
      
      /* Refresh : Display the curent time and the sub second on the LCD  */
      RTC_Time_Display(37, Black , RTC_Get_Time(SecondFraction , &RTC_TimeStruct));
    }
    else
    {
      /* Re-initialize the Display time on the LCD */
      RTC_Time_InitDisplay();
    }  
  }
}
/**
  * @brief  Main program.
  * @param  None
  * @retval None
  */
int main(void)
{
    /*!< At this stage the microcontroller clock setting is already configured,
         this is done through SystemInit() function which is called from startup
         file (startup_stm32f0xx.s) before to branch to application main.
         To reconfigure the default setting of SystemInit() function, refer to
         system_stm32f0xx.c file
       */

    /* USARTx configured as follow:
            - BaudRate = 115200 baud
            - Word Length = 8 Bits
            - One Stop Bit
            - No parity
            - Hardware flow control disabled (RTS and CTS signals)
            - Receive and transmit enabled
      */
    USART_InitStructure.USART_BaudRate = 115200;
    USART_InitStructure.USART_WordLength = USART_WordLength_8b;
    USART_InitStructure.USART_StopBits = USART_StopBits_1;
    USART_InitStructure.USART_Parity = USART_Parity_No;
    USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
    USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
    STM_EVAL_COMInit(COM1, &USART_InitStructure);

    /* GPIOC Periph clock enable */
    RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOC, ENABLE);

    /* Output a message on Hyperterminal using printf function */
    printf("\n\r  *********************** RTC Time Stamp Example ***********************\n\r");

    if (RTC_ReadBackupRegister(RTC_BKP_DR0) != 0x32F2)
    {
        /* RTC configuration  */
        RTC_Config();

        /* Configure the RTC data register and RTC prescaler */
        RTC_InitStructure.RTC_AsynchPrediv = AsynchPrediv;
        RTC_InitStructure.RTC_SynchPrediv = SynchPrediv;
        RTC_InitStructure.RTC_HourFormat = RTC_HourFormat_24;

        /* Check on RTC init */
        if (RTC_Init(&RTC_InitStructure) == ERROR)
        {
            printf("\n\r        /!\\***** RTC Prescaler Config failed ********/!\\ \n\r");
        }

        /* Configure the time register */
        RTC_TimeRegulate();
    }
    else
    {
        /* Check if the Power On Reset flag is set */
        if (RCC_GetFlagStatus(RCC_FLAG_PORRST) != RESET)
        {
            printf("\r\n Power On Reset occurred....\n\r");
        }
        /* Check if the Pin Reset flag is set */
        else if (RCC_GetFlagStatus(RCC_FLAG_PINRST) != RESET)
        {
            printf("\r\n External Reset occurred....\n\r");
        }

        printf("\r\n No need to configure RTC....\n\r");

        /* Enable the PWR clock */
        RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);

        /* Allow access to RTC */
        PWR_BackupAccessCmd(ENABLE);

        /* Wait for RTC APB registers synchronisation */
        RTC_WaitForSynchro();

        /* Clear the RTC Alarm Flag */
        RTC_ClearFlag(RTC_FLAG_ALRAF);

        /* Clear the EXTI Line 17 Pending bit (Connected internally to RTC Alarm) */
        EXTI_ClearITPendingBit(EXTI_Line17);

        /* Display the RTC Time/Date and TimeStamp Time/Date */
        RTC_TimeShow();
        RTC_DateShow();
        RTC_TimeStampShow();
    }

    /* Configure the external interrupt  "TAMPER" and "Joystick SEL" buttons */
    STM_EVAL_PBInit(BUTTON_TAMPER, BUTTON_MODE_EXTI);
    STM_EVAL_PBInit(BUTTON_KEY, BUTTON_MODE_EXTI);
    STM_EVAL_PBInit(BUTTON_SEL, BUTTON_MODE_EXTI);

    /* Configure LED1 */
    STM_EVAL_LEDInit(LED1);
    STM_EVAL_LEDOn(LED1);

    /* Infinite loop */
    while (1)
    {
    }
}
Esempio n. 29
0
u8 RT_Total_Config(void) 
{
   u8  Resualt=0;
   //表明RTC数据丢失,需要重新配置
    if (RTC_ReadBackupRegister(RTC_BKP_DR0) != RTC_First)
   {
	       rt_kprintf("rtc is not configured\n");
              //重新配置RTC
              RTC_Config();
	       // Check  resualt		  
		if ( RTC_Config() != 0)
			{
			   RTC_Config();
					rt_kprintf("rtc configure fail...Reconfig once\r\n");  
					return  0 ;
			}
		else
		{
		     /* Configure the RTC data register and RTC prescaler */
			RTC_InitStructure.RTC_AsynchPrediv = AsynchPrediv;
			RTC_InitStructure.RTC_SynchPrediv = SynchPrediv;
			RTC_InitStructure.RTC_HourFormat = RTC_HourFormat_24;

			/* Check on RTC init */
			if (RTC_Init(&RTC_InitStructure) == ERROR)
			{
				rt_kprintf("\n\r  /!\\***** RTC Prescaler Config failed ********/!\\ \n\r");
			}			
		 }
		//配置完成后,向后备寄存器中写特殊字符0xA5A5 
	        RTC_WriteBackupRegister(RTC_BKP_DR0, RTC_First);	 		

		 Resualt=1;
   }
    else
 { 
       
    /* Check if the Power On Reset flag is set */
    if (RCC_GetFlagStatus(RCC_FLAG_PORRST) != 0)
    {
       ;// rt_kprintf("\r\n Power On Reset occurred....\n\r");
    }
    /* Check if the Pin Reset flag is set */
    else if (RCC_GetFlagStatus(RCC_FLAG_PINRST) != 0)
    {
       ;//rt_kprintf("\r\n External Reset occurred....\n\r");
    }

   // rt_kprintf("\r\n No need to configure RTC....\n\r");
    
    /* Enable the PWR clock */
     RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);

    /* Allow access to RTC */
     PWR_BackupAccessCmd(ENABLE);  

    /* Wait for RTC APB registers synchronisation */
     RTC_WaitForSynchro();

     /* Clear the RTC Alarm Flag */
     RTC_ClearFlag(RTC_FLAG_ALRAF);
      
	/* Wait for RTC registers synchronization */
       RTC_WaitForSynchro();
	Resualt=0;				
 } 
   return Resualt; 
}
Esempio n. 30
0
/**
  * @brief  Main program.
  * @param  None
  * @retval None
  */
int main(void)
{
  /*!< At this stage the microcontroller clock setting is already configured, 
       this is done through SystemInit() function which is called from startup
       file (startup_stm32l1xx_xx.s) before to branch to application main.
       To reconfigure the default setting of SystemInit() function, refer to
       system_stm32l1xx.c file
     */
 
  uint32_t index = 0, tmp=0 ;
  
  /* Initialize the LCD */
  STM32L152D_LCD_Init(); 
  
  /* Clear the LCD */ 
  LCD_Clear(White);
  
  /* Set the LCD Back Color */
  LCD_SetBackColor(Blue);
  
  /* Set the LCD Text Color */
  LCD_SetTextColor(White);
  
  /* Displays MESSAGE1 on line 1 */
  LCD_DisplayStringLine(LINE(0), (uint8_t *)MESSAGE1);
  
  /* Set the LCD Back Color */
  LCD_SetBackColor(Cyan);
  
  /* Set the LCD Text Color */
  LCD_SetTextColor(Black);
  
  /* Draw lines */
  LCD_DrawUniLine(69, 121, 69,20);
  LCD_DrawUniLine(171, 121, 171, 20);
  
  /* Draw 4 lines  */
  LCD_DrawUniLine(70, 121, 120, 71);
  LCD_DrawUniLine(120, 71, 170,121);
  LCD_DrawUniLine(70, 20, 120, 70);
  LCD_DrawUniLine(120, 70, 170,20);
  
  /* Initailize the Display Picture */  
  for (index = 0; index < 100 ; index++)
  {
    if ((index % 2) ==0)
    {
      /* Set the LCD Text Color */
      LCD_SetTextColor(Blue);
      /* Draw Horizontal line */
      LCD_DrawLine(70 + (index/2) , 120 - (index/2)  , 101 - (index + 1) ,Horizontal);
      /* Set the LCD Text Color */
      LCD_SetTextColor(White);
      /* Draw Horizontal line */
      LCD_DrawLine(170 - (index/2) , 120 - (index/2)  , 101 - (index + 1) ,Horizontal);
    }
  }
  
  /* Set the LCD Text Color */
  LCD_SetTextColor(Blue); 
  /* Set the LCD Back Color */
  LCD_SetBackColor(White);
  
  /* Display String on the LCD  */
  LCD_DisplayStringLine(LINE(3), " Set Timer:");
  LCD_DisplayStringLine(95,     "   01:00 ");  
  
  /* Initialize Timer to 60 seconds */
  SecondNumb = 60;
  
  /* Configure the external interrupt "LEFT", "RIGHT" , "DOWN" and "UP" buttons */
  STM_EVAL_PBInit(BUTTON_RIGHT, BUTTON_MODE_EXTI);
  STM_EVAL_PBInit(BUTTON_LEFT, BUTTON_MODE_EXTI);
  STM_EVAL_PBInit(BUTTON_UP, BUTTON_MODE_EXTI);
  STM_EVAL_PBInit(BUTTON_DOWN, BUTTON_MODE_EXTI);
  
  /* Configure DOWN button in GPIO mode */  
   STM_EVAL_PBInit(BUTTON_DOWN, BUTTON_MODE_GPIO);  
  
  /* Configure the RTC peripheral by selecting the clock source.*/
  RTC_Config();
 
  /* Configure RTC AlarmA register to generate 8 interrupts per 1 Second */
  RTC_AlarmConfig();
  
  /* Set Text and Back color and Text size */
  LCD_SetFont(&Font12x12);
  LCD_SetBackColor(Cyan);
  LCD_SetTextColor(Black);
  LCD_DisplayStringLine(LINE(18), (uint8_t *)MESSAGE2);
  
  /* Set the LCD Back Color */
  LCD_SetBackColor(Blue);
  LCD_SetTextColor(White);
  LCD_DisplayStringLine(LINE(19), (uint8_t *)MESSAGE3);
  LCD_SetFont(&Font16x24);

  while (1)
  {
    /* Check on the event 'start' */
    if(StartEvent == 8)
    {
      /* Check on the Alarm event counter */
      if(RTCAlarmCount != 0 ) 
      {
        tmp = (uint32_t) ((RTCAlarmCount * 100)/ (8 * SecondNumb)); 
        
        /* First */
        Delay((1000* SecondNumb));
        
        LCD_SetTextColor(Blue);
        LCD_DrawLine(120, 70, 2, Vertical);
        LCD_DrawLine(122, 68, 2, Vertical);
        LCD_DrawLine(122, 72, 2, Vertical);
        if(tmp <= 72)
        {  
          LCD_SetTextColor(White);
          LCD_DrawLine(130, 70, 2, Vertical);
          LCD_DrawLine(132, 68, 2, Vertical);
          LCD_DrawLine(132, 72, 2, Vertical);
        }
        LCD_SetTextColor(Blue);
        LCD_DrawLine(140, 70, 2, Vertical);
        LCD_DrawLine(142, 69, 2, Vertical);
        LCD_DrawLine(142, 72, 2, Vertical);
        
        /* Second */
        Delay((1000*SecondNumb));
        if(tmp <= 90)
        { 
          LCD_SetTextColor(White);
          LCD_DrawLine(120, 70, 2, Vertical);
          LCD_DrawLine(122, 68, 2, Vertical);
          LCD_DrawLine(122, 72, 2, Vertical);
        }
        LCD_SetTextColor(Blue);
        LCD_DrawLine(130, 70, 2, Vertical);
        LCD_DrawLine(132, 68, 2, Vertical);
        LCD_DrawLine(132, 72, 2, Vertical);
        if(tmp <= 52)
        { 
          LCD_SetTextColor(White);
          LCD_DrawLine(140, 70, 2, Vertical);
          LCD_DrawLine(142, 68, 2, Vertical);
          LCD_DrawLine(142, 72, 2, Vertical);
        }
      }
    }
    else if (StartEvent == 9)
    {
      LCD_SetTextColor(Blue);
      LCD_DrawLine(120, 70, 2, Vertical);
      LCD_DrawLine(122, 68, 2, Vertical);
      LCD_DrawLine(122, 72, 2, Vertical);
      
      LCD_DrawLine(130, 70, 2, Vertical);
      LCD_DrawLine(132, 68, 2, Vertical);
      LCD_DrawLine(132, 72, 2, Vertical);
      
      LCD_DrawLine(140, 70, 2, Vertical);
      LCD_DrawLine(142, 68, 2, Vertical);
      LCD_DrawLine(142, 72, 2, Vertical);
    }
    else
    {
      if(tmp <= 90)
      { 
        LCD_SetTextColor(White);
      }
      else
      {
        LCD_SetTextColor(Blue);
      }
      LCD_DrawLine(120, 70, 2, Vertical);
      LCD_DrawLine(122, 68, 2, Vertical);
      LCD_DrawLine(122, 72, 2, Vertical);
      
      if(tmp <= 72)
      { 
        LCD_SetTextColor(White);
      }
      else
      {
        LCD_SetTextColor(Blue);
      }
      LCD_DrawLine(130, 70, 2, Vertical);
      LCD_DrawLine(132, 68, 2, Vertical);
      LCD_DrawLine(132, 72, 2, Vertical);
      
      if(tmp <= 52)
      { 
        LCD_SetTextColor(White);
      }
      else
      {
        LCD_SetTextColor(Blue);
      }
      LCD_DrawLine(140, 70, 2, Vertical);
      LCD_DrawLine(142, 68, 2, Vertical);
      LCD_DrawLine(142, 72, 2, Vertical);
      
    }
  }
}