滴答定时器定时:(放在主函数即可)
volatile unsigned int delay_times = 0;//搭配滴答定时器实现的精确ms延时
void delay_ms(unsigned int ms)
{delay_times = ms;while( delay_times != 0 );
} //滴答定时器中断
void SysTick_Handler(void)
{if( delay_times != 0 ){delay_times--;}
}
滴答定时器SYSCFG配置:
普通定时器.c文件:
#include "ti/driverlib/dl_gpio.h"
#include "ti/driverlib/m0p/dl_core.h"
#include "ti_msp_dl_config.h"
#include <stdint.h>
#include <stdio.h>//CPUCLK_FREQ 32000000 32000000/1000 = 32000 ->1ms
void delay_ms(uint32_t ms)
{while(ms--){delay_cycles(CPUCLK_FREQ/1000);}
}void delay_us(uint32_t us)
{while(us--){delay_cycles(CPUCLK_FREQ/1000000);}
}
普通定时器.h文件
#ifndef __DELAY_H
#define __DELAY_H#include <stdint.h>
void delay_ms(uint32_t ms);
void delay_us(uint32_t us);#endif