<meter id="pryje"><nav id="pryje"><delect id="pryje"></delect></nav></meter>
          <label id="pryje"></label>

          新聞中心

          EEPW首頁 > 嵌入式系統(tǒng) > 設(shè)計(jì)應(yīng)用 > stm32 的RTC 時(shí)鐘程序

          stm32 的RTC 時(shí)鐘程序

          作者: 時(shí)間:2016-11-11 來源:網(wǎng)絡(luò) 收藏
          前些日子做了stm32 RTC時(shí)鐘的程序,現(xiàn)在把它記錄下來。

          首先配置RTC,,使用外部時(shí)鐘32.768KHz。其中配置了秒中斷。

          本文引用地址:http://www.ex-cimer.com/article/201611/316828.htm

          RTCFirstConfigure()程序是第一次配置RTC,如果配置后以后上電不需要重新配置,如果RTC時(shí)鐘快了,可內(nèi)部校準(zhǔn)。

          void RTCFirstConfigure() //first ini
          {
          RCC_BackupResetCmd(ENABLE);
          RCC_BackupResetCmd(DISABLE);

          RCC_LSEConfig(RCC_LSE_ON); //enable LSE clock 32.768K
          while (RCC_GetFlagStatus(RCC_FLAG_LSERDY) == RESET)
          {}
          // Select LSE as RTC Clock Source
          RCC_RTCCLKConfig(RCC_RTCCLKSource_LSE);
          //Enable RTC Clock /
          RCC_RTCCLKCmd(ENABLE);
          // Wait for RTC registers synchronization /
          RTC_WaitForSynchro();
          // Wait until last write operation on RTC registers has finished /
          RTC_WaitForLastTask();
          // Enable the RTC Second Interrupt/
          RTC_ITConfig(RTC_IT_SEC, ENABLE);
          RTC_WaitForLastTask();
          RTC_SetPrescaler(32767); // RTC period = RTCCLK/RTC_PR = (32.768KHz)/(32767+1)/
          RTC_WaitForLastTask();

          // BKP_SetRTCCalibrationValue(120); //RTC Calibration

          RCC_ClearFlag();
          }

          RTCNorConfigure()程序配置完后每次上電都運(yùn)行的程序

          void RTCNorConfigure() //normal ini
          {
          RTC_WaitForSynchro();
          RTC_WaitForLastTask();
          RTC_SetPrescaler(32767);
          BKP_SetRTCCalibrationValue(0); //RTC Calibration
          RTC_ITConfig(RTC_IT_SEC, ENABLE);
          RTC_WaitForLastTask();
          RCC_ClearFlag();
          }

          int main(void)
          {
          /* System Clocks Configuration */
          RCC_Configuration();
          /* NVIC configuration */
          NVIC_Configuration();

          /* Configure the GPIO ports */
          GPIO_Configuration();

          UART_Configuration();
          if (BKP_ReadBackupRegister(BKP_DR1) != 0xA4A4) //
          //if(GPIO_ReadInputBit(GPIOA,GPIO_Pin_5)==0x01)
          {
          RTCFirstConfigure();
          Time_Adjust(2011,5,20,18,12,0);
          BKP_WriteBackupRegister(BKP_DR1, 0xA4A4);
          }
          else
          {
          RTCNorConfigure();
          }

          // BKP_WriteBackupRegister(BKP_DR2, 0x1234);

          while (1)
          {
          }
          }



          關(guān)鍵詞: stm32RTC時(shí)鐘程

          評(píng)論


          技術(shù)專區(qū)

          關(guān)閉
          看屁屁www成人影院,亚洲人妻成人图片,亚洲精品成人午夜在线,日韩在线 欧美成人 (function(){ var bp = document.createElement('script'); var curProtocol = window.location.protocol.split(':')[0]; if (curProtocol === 'https') { bp.src = 'https://zz.bdstatic.com/linksubmit/push.js'; } else { bp.src = 'http://push.zhanzhang.baidu.com/push.js'; } var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(bp, s); })();