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

          新聞中心

          EEPW首頁 > 嵌入式系統(tǒng) > 設(shè)計(jì)應(yīng)用 > stm32定時器2輸出10KHZ波形

          stm32定時器2輸出10KHZ波形

          作者: 時間:2016-11-27 來源:網(wǎng)絡(luò) 收藏
          緊接上一篇文章

          /*! @function
          ********************************************************************************


          º¯ÊýÃû :RCC_Configuration
          ¹¦ÄÜ :ʱÖÓÅäÖÃ
          ----------------------------------------------------------------------------------
          ²ÎÊý :ÎÞ
          ·µ»ØÖµ :ÎÞ
          ---------------------------------------------------------------------------------
          ʹÓõÄÈ«¾Ö±äÁ¿ºÎÞ
          ----------------------------------------------------------------------------------
          ×÷Õß :
          ʱ¼ä : 2012/10/17

          *******************************************************************************/
          static void RCC_Configuration(void)
          {
          ErrorStatus HSEStartUpStatus;

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

          RCC_ClocksTypeDef RccClocks;

          RCC_DeInit();
          RCC_HSEConfig(RCC_HSE_ON);
          HSEStartUpStatus = RCC_WaitForHSEStartUp();

          if(HSEStartUpStatus == SUCCESS)
          {
          /* ÑÔñHCLK¨AHBʱÖÓԴΪSYSCLK 1·ÖƵ */
          RCC_HCLKConfig(RCC_SYSCLK_Div1);

          /* ÑÔñPCLK2ʱÖÓԴΪ HCLK¨AHB 1·ÖƵ */
          RCC_PCLK2Config(RCC_HCLK_Div1);

          /* ÑÔñPCLK1ʱÖÓԴΪ HCLK¨AHB 2·ÖƵ */
          RCC_PCLK1Config(RCC_HCLK_Div2);

          /* ÉèÖÃFLASHÑÓʱÖÜÆÚÊýΪ2 */
          FLASH_SetLatency(FLASH_Latency_2);

          /* ʹÄÜFLASHԤȻº´æ */
          FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable);

          /* ÑÔñËøÏà»·¨PLLʱÖÓԴΪHSE 1·ÖƵ¬±¶ÆµÊýΪ9¬ÔòPLLÊä³öƵÂÊΪ 8MHz * 9 = 72MHz */
          RCC_PLLConfig(RCC_PLLSource_HSE_Div1, RCC_PLLMul_9);

          /* ʹÄÜPLL */
          RCC_PLLCmd(ENABLE);

          /*µÈ´ýPLLÊä³öÎȶ¨ */
          while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET);
          /* ÑÔñSYSCLKʱÖÓԴΪPLL */
          RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);

          /* µÈ´ýPLL³ÉΪSYSCLKʱÖÓÔ´ */
          while(RCC_GetSYSCLKSource() != 0x08);
          }

          /* ÅäÖÃSysTick */
          RCC_GetClocksFreq(&RccClocks);
          //SysTick_Config(RccClocks.HCLK_Frequency / OS_TICKS_PER_SEC);

          /* ´ò¿ªGPIOʱÖÓ */
          RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB |
          RCC_APB2Periph_GPIOC | RCC_APB2Periph_GPIOD| RCC_APB2Periph_GPIOE,
          ENABLE);
          RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);
          }

          /*! @function
          ********************************************************************************


          º¯ÊýÃû :NVIC_Configuration
          ¹¦ÄÜ :ÖжϿØÖÆÆ÷ÅäÖÃ
          ----------------------------------------------------------------------------------
          ²ÎÊý :ÎÞ
          ·µ»ØÖµ :ÎÞ
          ---------------------------------------------------------------------------------
          ʹÓõÄÈ«¾Ö±äÁ¿ºÎÞ
          ----------------------------------------------------------------------------------
          ×÷Õß :
          ʱ¼ä : 2012/10/17

          *******************************************************************************/
          static void NVIC_Configuration(void)
          {
          NVIC_InitTypeDef NVIC_InitStructure;

          #ifdef VECT_TAB_RAM
          /* Set the Vector Table base location at 0x20000000 */
          NVIC_SetVectorTable(NVIC_VectTab_RAM, 0x0);
          #else /* VECT_TAB_FLASH */
          /* Set the Vector Table base location at 0x08000000 */
          NVIC_SetVectorTable(NVIC_VectTab_FLASH , 0);
          #endif
          /* Configure one bit for preemption priority */
          NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);

          /* Enable the USART1 Interrupt */
          NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn;
          NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2;
          NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
          NVIC_Init(&NVIC_InitStructure);

          /* Enable the USART2 Interrupt */
          NVIC_InitStructure.NVIC_IRQChannel = USART2_IRQn;
          NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2;
          NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
          NVIC_Init(&NVIC_InitStructure);

          /* Enable the USART3 Interrupt */
          NVIC_InitStructure.NVIC_IRQChannel = USART3_IRQn;
          NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2;
          NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
          NVIC_Init(&NVIC_InitStructure);
          /* Enable the TIMER3 Interrupt */
          NVIC_InitStructure.NVIC_IRQChannel = TIM3_IRQn;
          NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2;
          NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
          NVIC_Init(&NVIC_InitStructure);
          /* Enable the TIMER3 Interrupt */
          NVIC_InitStructure.NVIC_IRQChannel = TIM2_IRQn;
          NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2;
          NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
          NVIC_Init(&NVIC_InitStructure);
          }

          //72M timer2
          //ÖжÏʱ¼äº¨720*10/72000000=0.1Ms=10K
          void Timer2_config() //ucosiiʱÖÓ
          {
          TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;

          TIM_TimeBaseStructure.TIM_Prescaler = 360-1; //36M/360=100K HZ
          TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; //ÏòÉϼÆÊý
          TIM_TimeBaseStructure.TIM_Period = 10; // ; //×°ÔØÖµÑÔñ 10K
          TIM_TimeBaseStructure.TIM_ClockDivision = 0;
          //TIM_TimeBaseStructure.TIM_RepetitionCounter = 4;
          TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure);

          TIM_ITConfig(TIM2,TIM_IT_Update|TIM_IT_Trigger,ENABLE);
          TIM_Cmd(TIM2, ENABLE);
          }

          void TIM2_IRQHandler(void)
          {

          if (TIM_GetITStatus(TIM2, TIM_IT_Update) != RESET) //¼ì²éÖ¸¶¨µÄTIMÖжϷÉúÓë·ñ:TIM ÖжÏÔ´
          {

          if(Ledflg==0)
          {
          GPIO_SetBits(GPIOC, GPIO_Pin_6);
          GPIO_SetBits(GPIOC, GPIO_Pin_7);
          Ledflg=1;
          }
          else
          {
          GPIO_ResetBits(GPIOC, GPIO_Pin_6);
          GPIO_ResetBits(GPIOC, GPIO_Pin_7);
          Ledflg=0;
          }
          Ledcnt=0;

          }
          TIM_ClearITPendingBit(TIM2, TIM_IT_Update ); //Çå³ýTIMxµÄÖжϴý´¦Àíλ:TIM ÖжÏÔ´

          }



          關(guān)鍵詞: stm32定時器2波

          評論


          技術(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); })();