打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
STM8S
 1 /* Includes ------------------------------------------------------------------*/ 2 #include "stm8s.h" 3  4 /* Private define ------------------------------------------------------------*/ 5 #define TIM4_PERIOD       124 6 /* Private variables ---------------------------------------------------------*/ 7 __IO uint32_t TimingDelay = 0; 8 /* Private function prototypes -----------------------------------------------*/ 9 void Delay(__IO uint32_t nTime);10 void TimingDelay_Decrement(void);11 static void TIM4_Config(void);12 13 /**14   * @brief  Main program.15   * @param  None16   * @retval None17   */18 void main(void)19 {20   /* TIM4 configuration -----------------------------------------*/21   TIM4_Config();    22   23   /* Insert 50 ms delay */24   Delay(50);25   }26 }27 28 /**29   * @brief  Configure TIM4 to generate an update interrupt each 1ms 30   * @param  None31   * @retval None32   */33 static void TIM4_Config(void)34 {35   /* TIM4 configuration:36    - TIM4CLK is set to 16 MHz, the TIM4 Prescaler is equal to 128 so the TIM1 counter37    clock used is 16 MHz / 128 = 125 000 Hz38   - With 125 000 Hz we can generate time base:39       max time base is 2.048 ms if TIM4_PERIOD = 255 --> (255 + 1) / 125000 = 2.048 ms40       min time base is 0.016 ms if TIM4_PERIOD = 1   --> (  1 + 1) / 125000 = 0.016 ms41   - In this example we need to generate a time base equal to 1 ms42    so TIM4_PERIOD = (0.001 * 125000 - 1) = 124 */43 44   /* Time base configuration */45   TIM4_TimeBaseInit(TIM4_PRESCALER_128, TIM4_PERIOD);46   /* Clear TIM4 update flag */47   TIM4_ClearFlag(TIM4_FLAG_UPDATE);48   /* Enable update interrupt */49   TIM4_ITConfig(TIM4_IT_UPDATE, ENABLE);50   51   /* enable interrupts */52   enableInterrupts();53 54   /* Enable TIM4 */55   TIM4_Cmd(ENABLE);56 }57 58 59 /**60   * @brief  Inserts a delay time.61   * @param  nTime: specifies the delay time length, in milliseconds.62   * @retval None63   */64 void Delay(__IO uint32_t nTime)65 {66   TimingDelay = nTime;67 68   while (TimingDelay != 0);69 }70 71 /**72   * @brief  Decrements the TimingDelay variable.73   * @param  None74   * @retval None75   */76 void TimingDelay_Decrement(void)77 {78   if (TimingDelay != 0x00)79   {80     TimingDelay--;81   }82 }
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
单片机系统的运行时间如何获取?
STM32 SysTick基于3.5库函数
关于STM32的systick定时器的详细说明
stm32f407之USART(操作寄存器)
STM32入门学习之systick定时器
例子 | 环形队列来实现串口数据接收
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服