[应用相关] SysTick(系统滴答定时器)操作

[复制链接]
1055|5
 楼主| Varus 发表于 2017-10-25 11:45 | 显示全部楼层 |阅读模式
基于STM32F103ZET6核心板,SysTick(系统滴答定时器)操作

SysTick(系统滴答定时器)操作.zip

666.28 KB, 下载次数: 8

mmuuss586 发表于 2017-10-25 13:23 | 显示全部楼层

谢谢分享
yiy 发表于 2017-10-25 18:40 | 显示全部楼层
103不知道用了多少片了,这个芯片用的人多,也容易学。
yiy 发表于 2017-10-25 18:41 | 显示全部楼层
  1. #include "stm32f10x.h"
  2. #include "SysTick.h"
  3. #include "led.h"

  4. /*
  5. * 函数名:main
  6. * 描述  :主函数
  7. * 输入  :无
  8. * 输出  :无
  9. */
  10. int main(void)
  11. {
  12.        
  13. SystemInit();        // 配置系统时钟为72M        
  14. LED_GPIO_Config(); //LED 端口初始化

  15.         /* 配置SysTick 为10us中断一次 */
  16.         SysTick_Init();
  17.        
  18.   while (1)
  19.   {
  20.        
  21.     LED( 0 );        
  22.     Delay_us(50000);    // 50000 * 10us = 500ms
  23.         LED( 1 );        
  24.         Delay_us(50000);
  25.                
  26.   }
  27. }


yiy 发表于 2017-10-25 18:41 | 显示全部楼层
  1. #include "SysTick.h"

  2. static __IO u32 TimingDelay;

  3. /*初始化  SysTick*/
  4. void SysTick_Init(void)
  5. {
  6.         /* SystemFrequency / 1000    1ms中断一次
  7.          * SystemFrequency / 100000         10us中断一次
  8.          * SystemFrequency / 1000000 1us中断一次
  9.          */
  10.         if (SysTick_Config(SystemFrequency / 100000))
  11.   {
  12.     /* Capture error */
  13.     while (1);
  14.   }
  15. }


  16. /*us延时程序,10us为一个单位 */
  17. void Delay_us(__IO u32 nTime)
  18. {
  19.   TimingDelay = nTime;

  20.   while(TimingDelay != 0);
  21. }


  22. /* 获取节拍程序,在 SysTick 中断函数 SysTick_Handler()调用         */  
  23. void TimingDelay_Decrement(void)
  24. {
  25.   if (TimingDelay != 0x00)
  26.   {
  27.     TimingDelay--;
  28.   }
  29. }

yiy 发表于 2017-10-25 18:42 | 显示全部楼层

  1. #include "led.h"

  2. /***************  配置LED用到的I/O口 *******************/
  3. void LED_GPIO_Config(void)       
  4. {
  5.   GPIO_InitTypeDef GPIO_InitStructure;
  6.   RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOC, ENABLE); // 使能PC端口时钟  
  7.   GPIO_InitStructure.GPIO_Pin =  GPIO_Pin_13 ;       
  8.   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;      
  9.   GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  10.   GPIO_Init(GPIOC, &GPIO_InitStructure);  //初始化PC端口
  11.   GPIO_SetBits(GPIOC, GPIO_Pin_13 );         // 关闭所有LED
  12. }



您需要登录后才可以回帖 登录 | 注册

本版积分规则

155

主题

703

帖子

1

粉丝
快速回复 在线客服 返回列表 返回顶部