Systick时钟定时

主函数

 1 /* Note:Your choice is C IDE */
 2 #include "stdio.h"
 3 #include "led.h"
 4 void main()
 5 {
 6    SystemInit();//初始化系统,使得系统频率为72兆
 7    systick_init();//配置Systick,使得1ms产生中断
 8    led_gpio_init();
 9    while(1)
10    {
11    
12    GPIO_Setbits(GPIO,GPIO_Pin_15);
13    delay_ms(1000);//延时
14    GPIO_ResetBits(GPIO,GPIO_Pin_15);
15    delay_ms(1000);
16    }
17 }

time函数

 1 /* Note:Your choice is C IDE */
 2 #include "stdio.h"
 3 /*
 4 *第一步:配置系统时钟 void SystemInit(void)
 5 *配置Systick  core_cm3.h
 6 *写SysTick中断处理函数
 7 *编写delay延迟函数
 8 */
 9 
10 _IO uint32_t TimeDelay;
11 
12 void systick_init(void)
13 {
14     //配置Systick重载值,系统时钟为72MHz
15     //设置72000,中断时间;72000*(1/72000000)=1ms
16     
17     if(SysTick_confing(72000)==1)
18     {
19         while(1);
20     }
21     /*
22     while(Systick_confing(72000)==1)
23     */
24 }
25 //中断函数
26 void TimingDelay_Decrement(void)
27 {
28     if(TimingDelay!=0x00)
29     {
30         TimingDelay--;    
31     }
32 }
33 
34 void sysTick_Handle()
35 {
36     
37 }
38 
39 //第四步
40 void delay_ms(_IO uint32_t nTime)
41 {
42     TimingDelay=ntime;//时钟滴答
43     while(TimingDelay!=0);
44 }
1 #ifndef _TIMER_H_
2 #define _TIMER_H_
3 #include "stm32f10x.h"
4 
5 
6 extern _IO uint32_t TimingDelay;//生命外面的变量
7 void systick_init(void);
8 void delay_ms(_IO uint32_t nTime)
9 #endif
原文地址:https://www.cnblogs.com/kinson/p/7868184.html