コード例 #1
0
ファイル: rtc.c プロジェクト: pyjhhh/stm32_f1x
 /**
  * @file   RTC_Init
  * @brief  RTC Initialization
  * @param  无
  * @retval 无
  */
void RTC_Init(void)
{
  if (BKP_ReadBackupRegister(BKP_DR1)!= 0xA5A5)
  {
    /* Backup data register value is not correct or not yet programmed (when
    the first time the program is executed) */
    printf("RTC not yet configured....\r\n");
    /* RTC Configuration */
     RTC_Configuration();
	   Time_Regulate();
	/* Adjust time by values entred by the user on the hyperterminal */
    printf("RTC configured....\r\n");
    BKP_WriteBackupRegister(BKP_DR1, 0xA5A5);
  }
  else
  {
    /* Check if the Power On Reset flag is set */
    if (RCC_GetFlagStatus(RCC_FLAG_PORRST) != RESET)
    {
      printf("Power On Reset occurred....\r\n");
    }
    /* Check if the Pin Reset flag is set */
    else if (RCC_GetFlagStatus(RCC_FLAG_PINRST) != RESET)
    {
      printf("External Reset occurred....\r\n");
    }

    printf("No need to configure RTC....\r\n");
    /* Wait for RTC registers synchronization */
    RTC_WaitForSynchro();

    /* Enable the RTC Second */
    RTC_ITConfig(RTC_IT_SEC, ENABLE);
    /* Wait until last write operation on RTC registers has finished */
    RTC_WaitForLastTask();
  }

   /* NVIC configuration */
   NVIC_Configuration();

#ifdef RTCClockOutput_Enable
  /* Enable PWR and BKP clocks */
  RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR | RCC_APB1Periph_BKP, ENABLE);

  /* Allow access to BKP Domain */
  PWR_BackupAccessCmd(ENABLE);

  /* Disable the Tamper Pin */
  BKP_TamperPinCmd(DISABLE); /* To output RTCCLK/64 on Tamper pin, the tamper
                                 functionality must be disabled */

  /* Enable RTC Clock Output on Tamper Pin */
  BKP_RTCOutputConfig(BKP_RTCOutputSource_CalibClock);
#endif

   /* Clear reset flags */
  RCC_ClearFlag();
  return;
}
コード例 #2
0
/**
  * @brief  Adjusts time.
  * @param  None
  * @retval None
  */
void Time_Adjust(void) {
  /* Wait until last write operation on RTC registers has finished */
  RTC_WaitForLastTask();
  /* Change the current time */
  RTC_SetCounter(Time_Regulate());
  /* Wait until last write operation on RTC registers has finished */
  RTC_WaitForLastTask();
}
コード例 #3
0
ファイル: main.c プロジェクト: szymon2103/Stm32
/**
  * @brief  Returns the time entered by user, using demo board keys.
  * @param  None
  * @retval None
  */
void Time_Adjust(void)
{
  /* Display the current time */
  Time_Display();

  /* Change the current time */
  Time_Regulate();
}
コード例 #4
0
ファイル: rtc.c プロジェクト: vcheung/STM32
/*
 * 函数名:Time_Adjust
 * 描述  :时间调节
 * 输入  :无
 * 输出  :无
 * 调用  :主函数调用
 */
void Time_Adjust(void)
{
	/* Wait until last write operation on RTC registers has finished */
	RTC_WaitForLastTask();
	/* Change the current time
	 * 将设置的初始时间值装入RTC计数器,RTC开始运行时,计数器里面的值
	 * 会在初始值的基础上自动一秒加1次 */
	RTC_SetCounter(Time_Regulate());
	/* Wait until last write operation on RTC registers has finished */
	RTC_WaitForLastTask();
}
コード例 #5
0
/*
 * 函数名:Time_Adjust
 * 描述  :时间调节
 * 输入  :用于读取RTC时间的结构体指针
 * 输出  :无
 * 调用  :外部调用
 */
void Time_Adjust(struct rtc_time *tm)
{
	  /* Wait until last write operation on RTC registers has finished */
	  RTC_WaitForLastTask();
	
	  /* Get time entred by the user on the hyperterminal */
	  Time_Regulate(tm);
	  
	  /* Get wday */
	  GregorianDay(tm);

	  /* 修改当前RTC计数寄存器内容 */
	  RTC_SetCounter(mktimev(tm));

	  /* Wait until last write operation on RTC registers has finished */
	  RTC_WaitForLastTask();
}
コード例 #6
0
ファイル: calendar.c プロジェクト: freemanqiu/STM3210E_Demo
/*******************************************************************************
* Function Name  : Time_PreAdjust
* Description    : Returns the time entered by user, using demoboard keys.
* Input          : None
* Output         : None
* Return         : None
*******************************************************************************/
static void Time_PreAdjust(void)
{
  RCC_AHBPeriphClockCmd(RCC_AHBPeriph_FSMC, ENABLE);
  /* Clear the LCD screen */
  LCD_Clear(White);

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

  if(BKP_ReadBackupRegister(BKP_DR1) != 0xA5A5)
  {
    RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR | RCC_APB1Periph_BKP, ENABLE);
    /* Allow access to BKP Domain */
    PWR_BackupAccessCmd(ENABLE);
   
    LCD_DisplayStringLine(Line7, "RTC Config PLZ Wait.");

    /* RTC Configuration */
    RTC_Configuration();
    LCD_DisplayStringLine(Line7, "       TIME         ");
    /* Clear Line8 */
    LCD_ClearLine(Line8);

    /* Display time separators ":" on Line4 */
    LCD_DisplayChar(Line8, 212, ':');
    LCD_DisplayChar(Line8, 166, ':');

    /* Display the current time */
    Time_Display(RTC_GetCounter());

    /* Wait until last write operation on RTC registers has finished */
    RTC_WaitForLastTask();  
    /* Change the current time */
    RTC_SetCounter(Time_Regulate());

    BKP_WriteBackupRegister(BKP_DR1, 0xA5A5);

    /* Clear Line7 */
    LCD_ClearLine(Line7);    
    /* Clear Line8 */
    LCD_ClearLine(Line8);    
    /* Adjust Date */
    Date_PreAdjust();    
  }
  else
  {  
    /* Clear Line8 */
    LCD_ClearLine(Line8);
    
    /* Display time separators ":" on Line4 */
    LCD_DisplayChar(Line8, 212, ':');
    LCD_DisplayChar(Line8, 166, ':');

    /* Display the current time */
    Time_Display(RTC_GetCounter());

    /* Wait until last write operation on RTC registers has finished */
    RTC_WaitForLastTask();  
    /* Change the current time */
    RTC_SetCounter(Time_Regulate());  
  }
}
コード例 #7
0
ファイル: Calendar.c プロジェクト: afxstar/Mplib
/*********************************************************************************************************
  * @brief  Calendar program.
  * @retval None
  ********************************************************************************************************/
void Calendar(void)
{
    CKCU_APBPerip1ClockConfig(CKCU_APBEN1_RTC, ENABLE);
    if(PWRCU_CheckReadyAccessed() != PWRCU_OK)
    {
        while(1);
    }

    /* Init LED3 and USART */
    LED_Configuration();
    USART_Configuration();

    /* Enable NVIC RTC interrupt */
    NVIC_EnableIRQ(RTC_IRQn);

    /* Check if the Power On Reset flag is set */
    if(PWRCU_GetFlagStatus() == PWRCU_FLAG_BAKPOR)
    {
        printf("\r\n\n Power On Reset occurred....");
    }

    if(PWRCU_ReadBackupRegister(PWRCU_BAKREG_0) != 0x5A5A)
    {
        u32 wInitTime = 0;
        /* Backup data register value is not correct or not yet programmed (when
           the first time the program is executed) */

        printf("\r\n\n RTC not yet configured....");

        /* RTC Configuration */
        RTC_Configuration();

        printf("\r\n RTC configured....");

        /* Adjust time by values entred by the user on the hyperterminal,
           Then store the init time to PWRCU_BAKREG_1. */
        wInitTime = Time_Regulate() ;
        PWRCU_WriteBackupRegister(PWRCU_BAKREG_1, wInitTime);

        /* Reset RTC Counter when Time is 23:59:59 */
        RTC_SetCompare(86400 - wInitTime) ;

        PWRCU_WriteBackupRegister(PWRCU_BAKREG_0, 0x5A5A);
        /* Enable RTC */
        RTC_Cmd(ENABLE) ;
    }
    else
    {
        printf("\r\n No need to configure RTC....");
    }

    /* Display current time in infinite loop */
    printf("\n\r");

    while (1)
    {
        /* If 1s has paased */
        if(gwTimeDisplay == 1)
        {
            /* Display current time.
               Current time is sum of the RTC counter value and the init time(stored in PWRCU_BAKREG_1 register).
               The init time (PWRCU_BAKREG_1 register) will be clear if the RTC Match flag(CMFLAG) is set.
               Refer to RTC_IRQHandler. */
            Time_Display(RTC_GetCounter() + PWRCU_ReadBackupRegister(PWRCU_BAKREG_1));
            gwTimeDisplay = 0;
        }
    }
}