实现流水灯以间隔500ms的时间闪烁(系统定时器SysTick实现的精确延时)
生活随笔
收集整理的這篇文章主要介紹了
实现流水灯以间隔500ms的时间闪烁(系统定时器SysTick实现的精确延时)
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
/** ****************************************************************************** * @file main.c * @author iuc * @version version 1.0 * @date 2015-5-19 19:37:52 * @brief 流水燈閃爍 ****************************************************************************** * @attention * 實現(xiàn)流水燈以間隔500ms的時間閃爍(系統(tǒng)定時器SysTick實現(xiàn)的精確延時) * ****************************************************************************** */ /* Includes ------------------------------------------------------------------*/ #include "stm32f10x.h" /* Private typedef -----------------------------------------------------------*/ /* Private define ------------------------------------------------------------*/ /* Private macro -------------------------------------------------------------*/ /* Private variables ---------------------------------------------------------*/ u32 temp = 0; /* Private function prototypes -----------------------------------------------*/ void Delay_SysTick_Init(void); void Led_Init(void); void Delay_us(unsigned n); /* Private functions ---------------------------------------------------------*/ /** * @brief * @param * @retval */ int main(void) { Led_Init(); Delay_SysTick_Init(); while(1) { GPIO_SetBits(GPIOD,GPIO_Pin_1); Delay_us(500); //延時500毫秒 GPIO_ResetBits(GPIOD,GPIO_Pin_1); Delay_us(500); } } void Led_Init(void) { GPIO_InitTypeDef GPIO_InitStructure; RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD,ENABLE); // 開啟時鐘 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_Init(GPIOD, &GPIO_InitStructure); } void Delay_SysTick_Init(void) { if(SysTick_Config(72000)) // 設置為計數(shù)72000次進入中斷一次,就是1毫秒進入中斷一次 { while(1); } SysTick->CTRL &= ~SysTick_CTRL_ENABLE_Msk; // 關閉滴答定時器,待需要的時候再打開 } void Delay_us(unsigned n) // 延時n毫秒 { temp = n; SysTick->CTRL |= SysTick_CTRL_ENABLE_Msk; // 開啟滴答定時器 while(temp != 0); }
轉載于:https://www.cnblogs.com/iucforever/p/4515382.html
總結
以上是生活随笔為你收集整理的实现流水灯以间隔500ms的时间闪烁(系统定时器SysTick实现的精确延时)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 【转】jQuery中的bind(),li
- 下一篇: 如何查看自己的ubutu系统是32位的还