定时器延时
#include "stm32f10x.h"
volatile uint32_t ms_ticks = 0;
void SysTick_Init(void)
{
if (SysTick_Config(SystemCoreClock / 1000))
{
// 错误处理
while (1);
}
}
void SysTick_Handler(void)
{
ms_ticks++;
}
void delay_ms(uint32_t ms)
{
uint32_t start_ticks = ms_ticks;
while ((ms_ticks - start_ticks) < ms);
}
int main(void)
{
SysTick_Init();
while(1)
{
LED1_ON();
delay_ms(500);
LED1_OFF();
delay_ms(500);
}
}
|