示例#1
0
/**
  * @brief  This function handles External lines 15 to 10 interrupt request.
  * @param  None
  * @retval None
  */
void EXTI15_10_IRQHandler(void)
{
  /* TimeStamp Event detected */
  if(EXTI_GetITStatus(TAMPER_BUTTON_EXTI_LINE) != RESET)
  {
    count++;
    
    /* Turn on LED2 and off LED1 */
    STM_EVAL_LEDOn(LED2);
    STM_EVAL_LEDOff(LED1);
    
    /* LCD display */
    LCD_ClearLine(LCD_LINE_2);
    LCD_DisplayStringLine(LCD_LINE_3,(uint8_t *) "TimeStamp Event Occurred      " );
    
    /* Display the TimeStamp */
    RTC_TimeStampShow();
    
    /* Display the date */
    RTC_DateShow();
    
    /* Display the Time */
    RTC_TimeShow();
    
    /* Clear the TAMPER Button EXTI line pending bit */
    EXTI_ClearITPendingBit(TAMPER_BUTTON_EXTI_LINE); 
  }
}
示例#2
0
/**
  * @brief  This function handles External lines 15 to 10 interrupt request.
  * @param  None
  * @retval None
  */
void EXTI15_10_IRQHandler(void)
{
  /* TimeStamp Event detected */
  if(EXTI_GetITStatus(TAMPER_BUTTON_EXTI_LINE) != RESET)
  {
    /* Turn LED4 ON */
    STM_EVAL_LEDOn(LED4);
    printf("\r\n******************** TimeStamp Event Occurred ********************");
    /* Clear the TAMPER Button EXTI line pending bit */
    EXTI_ClearITPendingBit(TAMPER_BUTTON_EXTI_LINE);
  }

  /* To display Current RTC Time and Date Calendar */
  if(EXTI_GetITStatus(KEY_BUTTON_EXTI_LINE) != RESET)
  {
    /* Turn LED4 ON */
    STM_EVAL_LEDOn(LED4);

    /* Clear the KEY Button EXTI line pending bit */
    EXTI_ClearITPendingBit(KEY_BUTTON_EXTI_LINE);

    /* Display the Time */
    RTC_TimeShow();
    /* Display the date */
    RTC_DateShow();
    /* Display the TimeStamp */
    RTC_TimeStampShow();
  }
}
void vTask3(void *pvParameters)
{
  while(1)
    {
      RTC_TimeShow();
      vTaskDelay(2000);
    }
}
示例#4
0
/**
  * @brief  Main program
  * @param  None
  * @retval None
  */
int main(void)
{
  /* STM32F4xx 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 180 MHz */
  SystemClock_Config();

  /* Configure LED1 and LED3 */
  BSP_LED_Init(LED1);
  BSP_LED_Init(LED3);

  /*##-1- Configure the RTC peripheral #######################################*/
  RtcHandle.Instance = RTC;

  /* Configure RTC prescaler and RTC data registers */
  /* RTC configured as follows:
      - Hour Format    = Format 24
      - Asynch Prediv  = Value according to source clock
      - Synch Prediv   = Value according to source clock
      - OutPut         = Output Disable
      - OutPutPolarity = High Polarity
      - OutPutType     = Open Drain */
  RtcHandle.Init.HourFormat     = RTC_HOURFORMAT_24;
  RtcHandle.Init.AsynchPrediv   = RTC_ASYNCH_PREDIV;
  RtcHandle.Init.SynchPrediv    = RTC_SYNCH_PREDIV;
  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();
  }

  /*##-2- Configure Alarm ####################################################*/
  /* Configure RTC Alarm */
  RTC_AlarmConfig();
  
  /* Infinite loop */  
  while (1)
  {
    /*##-3- Display the updated Time #########################################*/
    RTC_TimeShow(aShowTime);
  }
}
示例#5
0
/**
  * @brief  This function handles External lines 15 to 10 interrupt request.
  * @param  None
  * @retval None
  */
void EXTI15_10_IRQHandler(void)
{
   
  if(EXTI_GetITStatus(TAMPER_BUTTON_EXTI_LINE) != RESET)
  {
    /* Display the current time */
    RTC_TimeShow();
    
    /* Clear the Tamper Button EXTI line pending bit */
    EXTI_ClearITPendingBit(TAMPER_BUTTON_EXTI_LINE);
  }  
}
示例#6
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 and LED3 */
  BSP_LED_Init(LED1);
  BSP_LED_Init(LED3);

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

  /*##-1- Configure the RTC peripheral #######################################*/
  RtcHandle.Instance = RTC;

  /* Configure RTC prescaler and RTC data registers */
  /* RTC configured as follow:
      - Hour Format    = Format 24
      - Asynch Prediv  = Value according to source clock
      - Synch Prediv   = Value according to source clock
      - OutPut         = Output Disable
      - OutPutPolarity = High Polarity
      - OutPutType     = Open Drain */
  RtcHandle.Init.HourFormat = RTC_HOURFORMAT_24;
  RtcHandle.Init.AsynchPrediv = RTC_ASYNCH_PREDIV;
  RtcHandle.Init.SynchPrediv = RTC_SYNCH_PREDIV;
  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();
  }

  /*##-2- Configure Alarm ####################################################*/
  /* Configure RTC Alarm */
  RTC_AlarmConfig();

  /* Infinite loop */
  while (1)
  {
    /*##-3- Display the updated Time #########################################*/
    RTC_TimeShow(aShowTime);
  }
}
示例#7
0
/**
  * @brief  Main program
  * @param  None
  * @retval None
  */
int main(void)
{
  /* STM32F103xB 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 64 MHz */
  SystemClock_Config();

  /* Configure LED_GREEN */
  BSP_LED_Init(LED_GREEN);

  /*##-1- Configure the RTC peripheral #######################################*/
  RtcHandle.Instance = RTC;

  /* Configure RTC prescaler and RTC data registers */
  /* RTC configured as follows:
      - Asynch Prediv  = Automatic calculation of prediv for 1 sec timebase
  */
  RtcHandle.Init.AsynchPrediv = RTC_AUTO_1_SECOND;
  if (HAL_RTC_Init(&RtcHandle) != HAL_OK)
  {
    /* Initialization Error */
    Error_Handler();
  }

  /*##-2- Configure Alarm ####################################################*/
  /* Configure RTC Alarm */
  RTC_AlarmConfig();
  
  /* Infinite loop */  
  while (1)
  {
    /*##-3- Display the updated Time #########################################*/
    RTC_TimeShow(aShowTime);
  }
}
示例#8
0
/**
  * @brief  This function handles External line 9 to 5 interrupt request.
  * @param  None
  * @retval None
  */
void EXTI9_5_IRQHandler(void)
{
  if(EXTI_GetITStatus(KEY_BUTTON_EXTI_LINE) != RESET)
  {  
    /* Display the current time on the Hyperterminal */
    RTC_TimeShow();
     
    /* Clear the Key Button EXTI line pending bit */
    EXTI_ClearITPendingBit(KEY_BUTTON_EXTI_LINE);
  }
    if(EXTI_GetITStatus(UP_BUTTON_EXTI_LINE) != RESET)
  {  
    /* Display the current alarm on the Hyperterminal */
    RTC_AlarmShow();
     
    /* Clear the UP Button EXTI line pending bit */
    EXTI_ClearITPendingBit(UP_BUTTON_EXTI_LINE);
  }
}
示例#9
0
/**
  * @brief  This function handles External lines 15 to 10 interrupt request.
  * @param  None
  * @retval None
  */
void EXTI15_10_IRQHandler(void)
{
  if(EXTI_GetITStatus(KEY_BUTTON_EXTI_LINE) != RESET)
  {
    /* Display the current time on the Hyperterminal */
    RTC_TimeShow();

    /* Clear the Key Button EXTI line pending bit */
    EXTI_ClearITPendingBit(KEY_BUTTON_EXTI_LINE);
  }

  if(EXTI_GetITStatus(TAMPER_BUTTON_EXTI_LINE) != RESET)
  {
    /* Set the new RTC configuration */
     RTC_TimeRegulate();

    /* Clear the Tamper Button EXTI line pending bit */
    EXTI_ClearITPendingBit(TAMPER_BUTTON_EXTI_LINE);
  }
}
/**
  * @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)
    {
    }
}
/**
  * @brief  Returns the time entered by user, using Hyperterminal.
  * @param  None
  * @retval None
  */
void RTC_TimeRegulate(void)
{
    uint32_t tmp_hh = 0xFF, tmp_mm = 0xFF, tmp_ss = 0xFF;

    printf("\n\r==============Time Settings=====================================\n\r");
    RTC_TimeStructure.RTC_H12     = RTC_H12_AM;
    printf("  Please Set Hours\n\r");
    while (tmp_hh == 0xFF)
    {
        tmp_hh = USART_Scanf(0, 23);
        RTC_TimeStructure.RTC_Hours = tmp_hh;
    }
    printf(":  %0.2d\n\r", tmp_hh);

    printf("  Please Set Minutes\n\r");
    while (tmp_mm == 0xFF)
    {
        tmp_mm = USART_Scanf(0, 59);
        RTC_TimeStructure.RTC_Minutes = tmp_mm;
    }
    printf(":  %0.2d\n\r", tmp_mm);

    printf("  Please Set Seconds\n\r");
    while (tmp_ss == 0xFF)
    {
        tmp_ss = USART_Scanf(0, 59);
        RTC_TimeStructure.RTC_Seconds = tmp_ss;
    }
    printf(":  %0.2d\n\r", tmp_ss);

    /* Configure the RTC time register */
    if(RTC_SetTime(RTC_Format_BIN, &RTC_TimeStructure) == ERROR)
    {
        printf("\n\r>> !! RTC Set Time failed. !! <<\n\r");
    }
    else
    {
        printf("\n\r>> !! RTC Set Time success. !! <<\n\r");
        RTC_TimeShow();
        /* Indicator for the RTC configuration */
        RTC_WriteBackupRegister(RTC_BKP_DR0, 0x32F2);
    }

    tmp_hh = 0xFF;
    tmp_mm = 0xFF;
    tmp_ss = 0xFF;

    printf("\n\r==============Date Settings=====================================\n\r");

    printf("  Please Set WeekDay (01-07)\n\r");
    while (tmp_hh == 0xFF)
    {
        tmp_hh = USART_Scanf(1, 7);
        RTC_DateStructure.RTC_WeekDay = tmp_hh;
    }
    printf(":  %0.2d\n\r", tmp_hh);
    tmp_hh = 0xFF;
    printf("  Please Set Date (01-31)\n\r");
    while (tmp_hh == 0xFF)
    {
        tmp_hh = USART_Scanf(1, 31);
        RTC_DateStructure.RTC_Date = tmp_hh;
    }
    printf(":  %0.2d\n\r", tmp_hh);

    printf("  Please Set Month (01-12)\n\r");
    while (tmp_mm == 0xFF)
    {
        tmp_mm = USART_Scanf(1, 12);
        RTC_DateStructure.RTC_Month = tmp_mm;
    }
    printf(":  %0.2d\n\r", tmp_mm);

    printf("  Please Set Year (00-99)\n\r");
    while (tmp_ss == 0xFF)
    {
        tmp_ss = USART_Scanf(0, 99);
        RTC_DateStructure.RTC_Year = tmp_ss;
    }
    printf(":  %0.2d\n\r", tmp_ss);

    /* Configure the RTC date register */
    if(RTC_SetDate(RTC_Format_BIN, &RTC_DateStructure) == ERROR)
    {
        printf("\n\r>> !! RTC Set Date failed. !! <<\n\r");
    }
    else
    {
        printf("\n\r>> !! RTC Set Date success. !! <<\n\r");
        RTC_DateShow();
        /* Indicator for the RTC configuration */
        RTC_WriteBackupRegister(RTC_BKP_DR0, 0x32F2);
    }

}
示例#12
0
void RTC_Configuration(void) {
  EXTI_InitTypeDef EXTI_InitStructure;
  NVIC_InitTypeDef NVIC_InitStructure;
  
  /* If this is first time turn on the board */
  if (RTC_ReadBackupRegister(RTC_BKP_DR0) != 0x32F2) {  
    /* RTC configuration  */
    RTC_Config();
    /* Display the RTC Time and Alarm */
    RTC_TimeShow();
    RTC_AlarmShow();
  } else {  // If this is not the first time turn on the board
    /* Check if the Power On Reset flag is set */
    if (RCC_GetFlagStatus(RCC_FLAG_PORRST) != RESET) {
      /* Power On Reset occurred */
      printf("\r\n * Power On Reset occurred");
      
    /* Check if the Pin Reset flag is set */
    } else if (RCC_GetFlagStatus(RCC_FLAG_PINRST) != RESET) {
      /* External Reset occurred */
      printf("\r\n * External Reset occurred");
    }
    
    /* 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 and Alarm */
    RTC_TimeShow();
    RTC_AlarmShow();
  }
   
  /* RTC Alarm A Interrupt Configuration */
  /* EXTI configuration *********************************************************/
  EXTI_ClearITPendingBit(EXTI_Line17);
  EXTI_InitStructure.EXTI_Line = EXTI_Line17;
  EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
  EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising;
  EXTI_InitStructure.EXTI_LineCmd = ENABLE;
  EXTI_Init(&EXTI_InitStructure);
  
  EXTI_ClearITPendingBit(EXTI_Line22);
  EXTI_InitStructure.EXTI_Line = EXTI_Line22;
  EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
  EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising;
  EXTI_InitStructure.EXTI_LineCmd = ENABLE;
  EXTI_Init(&EXTI_InitStructure);
  
  /* Enable the RTC Wakeup Interrupt */
  NVIC_InitStructure.NVIC_IRQChannel = RTC_WKUP_IRQn;
  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  NVIC_Init(&NVIC_InitStructure); 
  
  /* Enable the RTC Alarm Interrupt */
  NVIC_InitStructure.NVIC_IRQChannel = RTC_Alarm_IRQn;
  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2;
  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  NVIC_Init(&NVIC_InitStructure); 
}
示例#13
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_xx.s) before to branch to application main.
       To reconfigure the default setting of SystemInit() function, refer to
       system_stm32f10x.c file
     */
  
  /* RCC configuration */
  RCC_Configuration();
  
  /* TIM4 configuration */
  TIM4_Configuration();
  
  /* UART4 configuration */
  UART4_Configuration();
  
  /* Configure SysTick for each 1us */  
  SysTick_Config(SystemCoreClock / 1000000);
  
  /* TLCD configuration */
  TLCD_Configuration();

  /* RTC Configuration */
  RTC_Configuration();
  
  /* WIZ820io SPI2 configuration */
  WIZ820io_SPI2_Configuration();  // one that is on left one
  
  /* WIZ820io SPI3 configuration */
  //WIZ820io_SPI3_Configuration();  // one that is on right one

  /* W5200 Configuration */
  Set_network();
  
  /* EXIT4(Mode select button) configuration */
  EXTILine4_Configuration();
  
  /* EXIT5(F_SYNC : 100Hz) configuration */
  EXTILine5_Configuration();
  
  /* EXIT6(F_SCLK : 10KHz) configuration */
  EXTILine6_Configuration();
  
  /* myAccel3LV02 Configuration */
  Accel3LV02_Configuration();
  
  //myAccel3LV02 setup 1000.0111 Power on, enable all axis, self test off
  Accel_WriteReg(CTRL_REG1, 0xC7);
  // following routine setup myAccel3LV02 6g mode
  //Accel_WriteReg(CTRL_REG2, 0x80);
  
  /* GLCD configuration */
  GLCD_Configuration();
  
  /* Clear system loading string of TLCD */
  TLCD_Clear();
  
  // When everything is set, print message
  printf("\r\n - System is ready - ");
  
  while(1) {
    if(TimerCount >= 1000) {  // thousand equals one second
      TimerCount = 0;

      /*
      // retrieve axis data
      GetAccelValue(AXIS_X, &Xdata);
      GetAccelValue(AXIS_Y, &Ydata);
      GetAccelValue(AXIS_Z, &Zdata);
      
      char str[30];
      sprintf(str, "%d,%d,%d", 0xFFF&Xdata, 0xFFF&Ydata, 0xFFF&Zdata);
      TLCD_Clear();
      TLCD_Write(0, 0, str);
      */
    }
    
    if(ParseUART4) {
      ParseUART4 = false; 
      
      // print Wiz810io configuration
      printSysCfg();
    }
    
    if(flag_uart == 1) {
      tmp_start = index;
    }
    
    // On every impulse out of 100Hz do the work
    if(RbitFlag) {
      RbitFlag = false;
      
      // copy to buffer
      mAxisBuf.tmp_data_x_lcd[index] = mAxisData.data_x[index];
      mAxisBuf.tmp_data_y_lcd[index] = mAxisData.data_y[index];
      mAxisBuf.tmp_data_z_lcd[index] = mAxisData.data_z[index];
      
      // Copy to Temporary GAL array
      CopyToTmpGalArray(index);
      
      // Cut off to 1G
      CutOffTo1G(index);
      
      // Calculate GAL and copy to single temporary GAL value
      CalculateGalAndCopyToGal(index);
      
      // Determine KMA scale
      DetermineKMA(index);
      
      /* PC Client Parsing routine ------------------------------------------------- */
      /* Set PCFlag indicate that we have valid connection from PC Client(port 7070) */
      if(PCFlag) {
        //PCFlag = false;
        
        char PC_Buf[20];
        sprintf(PC_Buf, "%+d,%+d,%+d\n",
                mAxisBuf.tmp_data_x_lcd[index],
                mAxisBuf.tmp_data_y_lcd[index],
                mAxisBuf.tmp_data_z_lcd[index]);
        // code for stacking algorithm which will combine data from two boards into one
        // Only when socket is established, allow send data
        if(getSn_SR(SOCK_TWO) == SOCK_ESTABLISHED) {
          /* send selected data */
          send(SOCK_TWO, (uint8_t*)PC_Buf, strlen(PC_Buf), (bool)false);
        }
      }
      
      // increase index so that we can add to next array
      index++;
    }
        
    switch(mode) {
    case SELECT_AXIS_X : break;
    case SELECT_AXIS_Y : break;
    case SELECT_AXIS_Z : break;
    }
    
    // RTC Wakeup event
    if(WUFlag) {
      WUFlag = false;
      
      // Update current Date and Time
      RTC_TimeShow();
      
      // Display on TLCD
      TLCD_Write(0, 0, Date);
      TLCD_Write(0, 1, Time);
    }
    
    /* EQ-DAQ-01 Parsing routine ------------------------------------------------- */
    /* Set E1Flag indicate that we have valid connection from EQ-DAQ-01(port 5050) */
    if(E1Flag) {
      E1Flag = false;
      
      ProcessTextStream(EQ_ONE, (char*)RX_BUF);
    }
    
    /* EQ-DAQ-02 Parsing routine ------------------------------------------------- */
    /* Set E2Flag indicate that we have valid connection from EQ-DAQ-02(port 6060) */
    if(E2Flag) {
      E2Flag = false;
      
      ProcessTextStream(EQ_TWO, (char*)RX_BUF);
    }
    
    /* Process server socket with each port */
    ProcessTcpServer(SOCK_ZERO, 5050);  // designated as for EQM-DAQ-01 with port 5050
    ProcessTcpServer(SOCK_ONE, 6060);   // designated as for EQM-DAQ-02 with port 6060
    ProcessTcpServer(SOCK_TWO, 7070);   // designated as for PC-CLIENT  with port 7070
    ProcessTcpServer(SOCK_THREE, 8080); // designated as for TOBEUSED   with port 8080
    
    /* Socket 4 to 7 reserved for future application
     * ProcessTcpServer(SOCK_FOUR, 9090);   // designated as for TOBEUSED with port 9090
     * ProcessTcpServer(SOCK_FIVE, 10010);   // designated as for TOBEUSED with port 10010
     * ProcessTcpServer(SOCK_SIX, 10020);    // designated as for TOBEUSED with port 10020
     * ProcessTcpServer(SOCK_SEVEN, 10030);  // designated as for TOBEUSED with port 10030
     */
  }
}
示例#14
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
       */

    /* Configure the external interrupt "WAKEUP" and "TAMPER" buttons */
    STM_EVAL_PBInit(BUTTON_TAMPER , BUTTON_MODE_EXTI);
    STM_EVAL_PBInit(BUTTON_WAKEUP , BUTTON_MODE_EXTI);

    /* Initialize LEDs and LCD available on EVAL board */
    STM_EVAL_LEDInit(LED1);
    STM_EVAL_LEDInit(LED2);

    /* Initialize the LCD */
    LCD_Init();
    LCD_Clear(LCD_COLOR_WHITE);

    /* Set the Back Color */
    LCD_SetBackColor(LCD_COLOR_BLUE);

    /* Set the Text Color */
    LCD_SetTextColor(LCD_COLOR_WHITE);

    LCD_DisplayStringLine(LCD_LINE_0,(uint8_t *) "  TimeStamp Example " );

    LCD_SetFont(&Font12x12);

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

        /* Configure the time&date register */
        RTC_TimeRegulate();

        /* Display the Date and Time */
        RTC_DateShow();
        RTC_TimeShow();

    }
    else
    {
        /* Check if the Power On Reset flag is set */
        if (RCC_GetFlagStatus(RCC_FLAG_PORRST) != RESET)
        {
            /* Set the Back Color */
            LCD_SetBackColor(LCD_COLOR_WHITE);

            /* Set the Text Color */
            LCD_SetTextColor(LCD_COLOR_GREEN);
            LCD_DisplayStringLine(LCD_LINE_2,(uint8_t *) "Power On Reset occurred       " );
        }
        /* Check if the Pin Reset flag is set */
        else if (RCC_GetFlagStatus(RCC_FLAG_PINRST) != RESET)
        {
            /* Set the Back Color */
            LCD_SetBackColor(LCD_COLOR_WHITE);

            /* Set the Text Color */
            LCD_SetTextColor(LCD_COLOR_GREEN);
            LCD_DisplayStringLine(LCD_LINE_2,(uint8_t *) "External Reset occurred      " );
        }

        /* Set the Back Color */
        LCD_SetBackColor(LCD_COLOR_WHITE);

        /* Set the Text Color */
        LCD_SetTextColor(LCD_COLOR_GREEN);
        LCD_DisplayStringLine(LCD_LINE_3,(uint8_t *) "No need to configure RTC     " );

        /* 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_DateShow();
        RTC_TimeShow();

    }

    while (1)
    {
    }
}
示例#15
0
/**
  * @brief  Main program
  * @param  None
  * @retval None
  */
void RTCTime_Test(void)
{
    uart_init();

    /* 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();
    }

    PUTOUT_KeyInit();
    
    while (1)
    {
    
    }
}
示例#16
0
void UDisk_Write_Test(void)
{ 
       rt_err_t res;
	 
      sec_num++; 
      if(sec_num==400)
	  	sec_num=0;  
	if(sec_num==0)
	{   
	      rt_kprintf("\r\n  Sec_num=0\r\n");  
	      //------ U disk
              Udisk_dev=rt_device_find("udisk");
	        if (Udisk_dev != RT_NULL)	    
		{       rt_kprintf("\r\n  Udiskopen");
                       
			  res=rt_device_open(Udisk_dev, RT_DEVICE_OFLAG_RDWR); 	
			 if(res==RT_EOK)
			 {
			    memset(Udisk_filename,0,sizeof(Udisk_filename));
			    RTC_TimeShow();	
			    sprintf((char*)Udisk_filename,"/udisk/ud%d%d%d.txt", time_now.hour,time_now.min, time_now.sec);  	
			    rt_kprintf("\r\n   UdiskFilename:%s\r\n",Udisk_filename);
			    udisk_fd=open((char*)Udisk_filename, O_RDWR|O_CREAT, 0); 
			     Udisk_Test_workState=1;   	 
			 }		 
		}  
	       else
		 { 
                      Udisk_Test_workState=0;
	        }
		  
             //----  TF---
          #if  1   
		/*  if(dfs_mount("spi_sd","/sd","elm",0,0))
		  	{
		  	     rt_kprintf("\r\n   TF errror\r\n");
		  	      return ;
		  	}
		  	*/
		  TF_dev=rt_device_find("spi_sd");
	        if (TF_dev != RT_NULL)	     
		{
                       rt_kprintf("\r\n  TFopen\r\n");  
			   res=rt_device_open(TF_dev, RT_DEVICE_OFLAG_RDWR); 
			  if(res==RT_EOK)
			 {
			   memset(TF_filename,0,sizeof(TF_filename));
			    RTC_TimeShow();	
			   sprintf((char*)TF_filename,"/sd/tf%d%d%d.txt",time_now.hour,time_now.min, time_now.sec); 
			    rt_kprintf("\r\n   TF_Filename:%s\r\n",TF_filename);       
			  TF_fd=open((char*)TF_filename, O_RDWR|O_CREAT, 0); 
			  TF_test_workState=1; 
			  }
		} 
		else
		  { 
		          rt_kprintf("\r\n  TF not find");   
                      TF_test_workState=0;
	        }
			
	  #endif	
	}


	if(sec_num==390)  
	{
	       //----  udisk
	      if((Udisk_Test_workState)&&(udisk_fd)) 
             {
                  close(udisk_fd);
		    rt_kprintf("\r\n   Udisk Filename:%s    close\r\n",Udisk_filename); 
			
	       }
	#if  1	  
              //  ----  tf 
            if((TF_test_workState)&&(TF_fd))
		{
		    close(TF_fd); 
		    rt_kprintf("\r\n  TF_ Filename:%s    close\r\n",TF_filename); 	   
            	}
	#endif		
	}
}
示例#17
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_stm32f4xx.s) before to branch to application main.
       To reconfigure the default setting of SystemInit() function, refer to
       system_stm32f4xx.c file
     */     
    NVIC_InitTypeDef  NVIC_InitStructure;
    EXTI_InitTypeDef  EXTI_InitStructure;

    LEDGpio_Init();
    EXTILine0_Config();  
    EXTILine6_Config();
    uart_init();
    /* Output a message on Hyperterminal using printf function */
    printf("\n\r  *********************** RTC Hardware Calendar 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("\n\r 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 and Alarm */
        RTC_TimeShow();
        RTC_AlarmShow();
  }
   
//  /* Configure the external interrupt "WAKEUP", "KEY" and "TAMPER" buttons */
//  STM_EVAL_PBInit(BUTTON_KEY, BUTTON_MODE_EXTI); 
//  STM_EVAL_PBInit(BUTTON_TAMPER , BUTTON_MODE_EXTI);
//  STM_EVAL_PBInit(BUTTON_WAKEUP , BUTTON_MODE_EXTI);
//
//  /* Configure LEDx */
//  STM_EVAL_LEDInit(LED1);
//  STM_EVAL_LEDInit(LED2);
//
//  /* Turn LED1 ON */
//  STM_EVAL_LEDOn(LED2);

    /* RTC Alarm A Interrupt Configuration */
    /* EXTI configuration *********************************************************/
    EXTI_ClearITPendingBit(EXTI_Line17);
    EXTI_InitStructure.EXTI_Line = EXTI_Line17;
    EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
    EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising;
    EXTI_InitStructure.EXTI_LineCmd = ENABLE;
    EXTI_Init(&EXTI_InitStructure);
    
    /* Enable the RTC Alarm Interrupt */
    NVIC_InitStructure.NVIC_IRQChannel = RTC_Alarm_IRQn;
    NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
    NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
    NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
    NVIC_Init(&NVIC_InitStructure);
    
    while (1)
    {
    }
}
示例#18
0
/**
  * @brief  Main program.
  * @param  None
  * @retval None
  */
void RTC_Calendar_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
     */

  NVIC_InitTypeDef  NVIC_InitStructure;
  EXTI_InitTypeDef  EXTI_InitStructure;
       
  /* 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);

  /* Output a message on Hyperterminal using printf function */
  printf("\n\r  *********************** RTC Hardware Calendar Example ***********************\n\r");
#if defined (RTC_CLOCK_SOURCE_LSI)   
    RCC_LSICmd(ENABLE);
#endif  

  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("\n\r 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 and Alarm */
    RTC_TimeShow();
    RTC_AlarmShow();
  }
   
  /* Configure the external interrupt "KEY", "SEL" and "UP" buttons */
  STM_EVAL_PBInit(BUTTON_KEY, BUTTON_MODE_EXTI); 
  STM_EVAL_PBInit(BUTTON_SEL, BUTTON_MODE_EXTI);
  STM_EVAL_PBInit(BUTTON_UP, BUTTON_MODE_EXTI);

  /* Configure LEDs */
  STM_EVAL_LEDInit(LED1);
  STM_EVAL_LEDInit(LED2);

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

  /* RTC Alarm A Interrupt Configuration */
  /* EXTI configuration *******************************************************/
  EXTI_ClearITPendingBit(EXTI_Line17);
  EXTI_InitStructure.EXTI_Line = EXTI_Line17;
  EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
  EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising;
  EXTI_InitStructure.EXTI_LineCmd = ENABLE;
  EXTI_Init(&EXTI_InitStructure);
  
  /* Enable the RTC Alarm Interrupt */
  NVIC_InitStructure.NVIC_IRQChannel = RTC_Alarm_IRQn;
  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  NVIC_Init(&NVIC_InitStructure);

  /* Infinite loop */
  while (1)
  {
  }
}
示例#19
0
/**
  * @brief  Returns the time entered by user, using Hyperterminal.
  * @param  None
  * @retval None
  */
void RTC_TimeRegulate(void)
{
  uint32_t tmp_hh = 0xFF, tmp_mm = 0xFF, tmp_ss = 0xFF;

  printf("\n\r==============Time Settings=====================================\n\r");
  RTC_TimeStructure.RTC_H12     = RTC_H12_AM;
  printf("  Please Set Hours:\n\r");
  while (tmp_hh == 0xFF)
  {
    tmp_hh = USART_Scanf(23);
    RTC_TimeStructure.RTC_Hours = tmp_hh;
  }
  printf("  %u\n\r", tmp_hh);
  
  printf("  Please Set Minutes:\n\r");
  while (tmp_mm == 0xFF)
  {
    tmp_mm = USART_Scanf(59);
    RTC_TimeStructure.RTC_Minutes = tmp_mm;
  }
  printf("  %0.2d\n\r", tmp_mm);
  
  printf("  Please Set Seconds:\n\r");
  while (tmp_ss == 0xFF)
  {
    tmp_ss = USART_Scanf(59);
    RTC_TimeStructure.RTC_Seconds = tmp_ss;
  }
  printf("  %0.2d\n\r", tmp_ss);

  /* Configure the RTC time register */
  if(RTC_SetTime(RTC_Format_BIN, &RTC_TimeStructure) == ERROR)
  {
    printf("\n\r>> !! RTC Set Time failed. !! <<\n\r");
  } 
  else
  {
    printf("\n\r>> !! RTC Set Time success. !! <<\n\r");
    RTC_TimeShow();
    /* Indicator for the RTC configuration */
    RTC_WriteBackupRegister(RTC_BKP_DR0, 0x32F2);
  }

  tmp_hh = 0xFF;
  tmp_mm = 0xFF;
  tmp_ss = 0xFF;

  /* Disable the Alarm A */
  RTC_AlarmCmd(RTC_Alarm_A, DISABLE);

  printf("\n\r==============Alarm A Settings=====================================\n\r");
  RTC_AlarmStructure.RTC_AlarmTime.RTC_H12 = RTC_H12_AM;
  printf("  Please Set Alarm Hours:\n\r");
  while (tmp_hh == 0xFF)
  {
    tmp_hh = USART_Scanf(23);
    RTC_AlarmStructure.RTC_AlarmTime.RTC_Hours = tmp_hh;
  }
  printf("  %0.2d\n\r", tmp_hh);
  
  printf("  Please Set Alarm Minutes:\n\r");
  while (tmp_mm == 0xFF)
  {
    tmp_mm = USART_Scanf(59);
    RTC_AlarmStructure.RTC_AlarmTime.RTC_Minutes = tmp_mm;
  }
  printf("  %0.2d\n\r", tmp_mm);
  
  printf("  Please Set Alarm Seconds:\n\r");
  while (tmp_ss == 0xFF)
  {
    tmp_ss = USART_Scanf(59);
    RTC_AlarmStructure.RTC_AlarmTime.RTC_Seconds = tmp_ss;
  }
  printf("  %0.2d", tmp_ss);

  /* Set the Alarm A */
  RTC_AlarmStructure.RTC_AlarmDateWeekDay = RTC_Weekday_Monday;
  RTC_AlarmStructure.RTC_AlarmDateWeekDaySel = RTC_AlarmDateWeekDaySel_Date;
  RTC_AlarmStructure.RTC_AlarmMask = RTC_AlarmMask_DateWeekDay;

  /* Configure the RTC Alarm A register */
  RTC_SetAlarm(RTC_Format_BIN, RTC_Alarm_A, &RTC_AlarmStructure);
  printf("\n\r>> !! RTC Set Alarm success. !! <<\n\r");
  RTC_AlarmShow();

  /* Enable the RTC Alarm A Interrupt */
  RTC_ITConfig(RTC_IT_ALRA, ENABLE);
   
  /* Enable the alarm  A */
  RTC_AlarmCmd(RTC_Alarm_A, ENABLE);
}
/**
  * @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_stm32f4xx.s) before to branch to application main.
       To reconfigure the default setting of SystemInit() function, refer to
       system_stm32f4xx.c file
     */     
#if defined (RTC_CLOCK_SOURCE_LSI) 
  /* Enable the LSI OSC */ 
  RCC_LSICmd(ENABLE);
#endif /* RTC_CLOCK_SOURCE_LSI */
  
  /* Configure the external interrupt "WAKEUP" and "TAMPER" buttons */ 
  STM_EVAL_PBInit(BUTTON_TAMPER , BUTTON_MODE_EXTI);
  STM_EVAL_PBInit(BUTTON_SEL , BUTTON_MODE_EXTI);

  /* Configure LEDs */
  STM_EVAL_LEDInit(LED1);
  STM_EVAL_LEDInit(LED2);
  STM_EVAL_LEDOn(LED1);
  
  /* Initialize the LCD */
#ifdef USE_STM320518_EVAL
    STM320518_LCD_Init();
#else
    STM32072B_LCD_Init();
#endif /* USE_STM320518_EVAL */

  /* Clear the LCD */ 
  LCD_Clear(White);
  
  /* Enable The Display */
  LCD_DisplayOn(); 
  
  /* Set the LCD Back Color and Text Color*/
  LCD_SetBackColor(Blue);
  LCD_SetTextColor(White);

 
  LCD_DisplayStringLine(LCD_LINE_0,(uint8_t *) "  TimeStamp Example " );
  
  /* Set the LCD Text size */
  LCD_SetFont(&Font16x24);
  
  if (RTC_ReadBackupRegister(RTC_BKP_DR0) != 0x32F2)
  {
    /* RTC configuration  */
    RTC_Config();

    /* Configure the time&date register */
    RTC_TimeRegulate(); 
    
    /* Display the Date */
    RTC_DateShow();
    
    /* Display the Time */
    RTC_TimeShow();
    
  }
  else
  {
    /* Check if the Power On Reset flag is set */
    if (RCC_GetFlagStatus(RCC_FLAG_PORRST) != RESET)
    {
      /* Set the Back Color */
      LCD_SetBackColor(LCD_COLOR_CYAN);
      
      /* Set the Text Color */
      LCD_SetTextColor(LCD_COLOR_BLACK);
      LCD_SetFont(&Font12x12);
      LCD_DisplayStringLine(LCD_LINE_2,(uint8_t *) "  Power On Reset occurred        " );
    }
    /* Check if the Pin Reset flag is set */
    else if (RCC_GetFlagStatus(RCC_FLAG_PINRST) != RESET)
    {
      /* Set the Back Color */
      LCD_SetBackColor(LCD_COLOR_CYAN);
      
      /* Set the Text Color */
      LCD_SetTextColor(LCD_COLOR_BLACK);
      LCD_SetFont(&Font12x12);
      LCD_DisplayStringLine(LCD_LINE_2,(uint8_t *) "  External Reset occurred       " );
    }

    /* Set the Back Color */
    LCD_SetBackColor(LCD_COLOR_CYAN);
    
    /* Set the Text Color */
    LCD_SetTextColor(LCD_COLOR_BLACK);
    LCD_SetFont(&Font12x12);
    LCD_DisplayStringLine(LCD_LINE_3,(uint8_t *) " No need to configure RTC     " );
    
    /* 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_DateShow();
    RTC_TimeShow();

  }
   
  while (1)
  {
    if (Button_State == TAMPER_ON)
    {
      /* Turn LED4 ON */
      STM_EVAL_LEDOn(LED2);
      LCD_SetFont(&Font12x12);
      LCD_DisplayStringLine(LCD_LINE_5,(uint8_t *) " TimeStamp Event Occurred      " );
      LCD_SetFont(&Font16x24);
      LCD_ClearLine(LCD_LINE_4);
      LCD_ClearLine(LCD_LINE_5);
      LCD_ClearLine(LCD_LINE_6);
      LCD_ClearLine(LCD_LINE_7);
      LCD_ClearLine(LCD_LINE_8);
      /* Display the TimeStamp */
      RTC_TimeStampShow();
      Button_State = 0;
    }
    else if (Button_State == SEL_ON)
    {
      /* Turn LED1 ON and LED2 OFF */
      STM_EVAL_LEDOn(LED1);
      STM_EVAL_LEDOff(LED2);
      
      /* Clear The TSF Flag (Clear TimeStamp Registers) */
      RTC_ClearFlag(RTC_FLAG_TSF);
      LCD_SetFont(&Font12x12);
      LCD_ClearLine(LCD_LINE_5);
      LCD_SetFont(&Font12x12);
      LCD_DisplayStringLine(LCD_LINE_5,(uint8_t *) " TimeStamp Event Cleared        " );
      Button_State = 0;
    }
  }
}