標(biāo)題: STM8L0單片機(jī)定時(shí)器程序 [打印本頁(yè)]

作者: tang200858    時(shí)間: 2020-9-6 20:46
標(biāo)題: STM8L0單片機(jī)定時(shí)器程序

  1. /* Includes ------------------------------------------------------------------*/
  2. #include "stm8l10x.h"
  3. //定義LED、按鍵接口
  4. #define LED_GPIO_PORT  GPIOD
  5. #define LED_GPIO_PINS  GPIO_Pin_0
  6. #define KEY_GPIO_PORT  GPIOB
  7. #define KEY_GPIO_PINS  GPIO_Pin_1
  8. /*******************************************************************************
  9. ****入口參數(shù):無(wú)
  10. ****出口參數(shù):無(wú)
  11. ****函數(shù)備注:不精確延時(shí)函數(shù)
  12. ****版權(quán)信息:藍(lán)旗嵌入式系統(tǒng)
  13. *******************************************************************************/
  14. void Delay(__IO uint16_t nCount)
  15. {
  16.     /* Decrement nCount value */
  17.     while (nCount != 0)
  18.     {
  19.         nCount--;
  20.     }
  21. }
  22. /*******************************************************************************
  23. ****入口參數(shù):無(wú)
  24. ****出口參數(shù):無(wú)
  25. ****函數(shù)備注:主函數(shù),PD0接LED,灌流,LED大約1S閃爍頻率
  26. ****版權(quán)信息:藍(lán)旗嵌入式系統(tǒng)
  27. *******************************************************************************/
  28. void main(void)
  29. {
  30.     GPIO_Init(LED_GPIO_PORT, LED_GPIO_PINS, GPIO_Mode_Out_PP_Low_Slow);//初始化LED,GPD0低速推挽輸出
  31.    
  32.     CLK_PeripheralClockConfig (CLK_Peripheral_TIM4,ENABLE); //使能外設(shè)時(shí)鐘,STM8L外設(shè)時(shí)鐘默認(rèn)關(guān)閉,使用前需使能
  33.    
  34.     TIM4_DeInit();
  35.     TIM4_TimeBaseInit(TIM4_Prescaler_128, 0xff);//16M/8/128=15.625K,0xff=255,255*(1/15.625)=0.01632S,大約61次中斷是1S
  36.    
  37.     TIM4_ITConfig(TIM4_IT_Update, ENABLE);//向上溢出中斷使能,中斷向量號(hào)25
  38.     TIM4_Cmd(ENABLE);//TIM4使能
  39.     enableInterrupts();//開(kāi)啟中斷總開(kāi)關(guān)
  40.     while(1)
  41.     {
  42.       

  43.     }

  44. }
  45.   
  46. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
復(fù)制代碼


定時(shí)器TIM4定時(shí)中斷.7z

286.12 KB, 下載次數(shù): 7, 下載積分: 黑幣 -5






歡迎光臨 (http://www.torrancerestoration.com/bbs/) Powered by Discuz! X3.1