延时Delay
Posted polarbearinbrown
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了延时Delay相关的知识,希望对你有一定的参考价值。
unsigned int Base_us;
unsigned int Base_ms;
void DELAY_Init(void)
{
SysTick_CLKSourceConfig(SysTick_CLKSource_HCLK_Div8);
Base_us = SystemCoreClock/8000000;
Base_ms = Base_us*1000;
}
void DELAY_us(unsigned int n)
{
unsigned int Temp;
SysTick->LOAD = n*Base_us;
SysTick->VAL = 0x00;
SysTick->CTRL|= SysTick_CTRL_ENABLE_Msk;
do
{
Temp = SysTick->CTRL;
}while((Temp&0x01)&&!(Temp&(1<<16)));
SysTick->CTRL &= ~SysTick_CTRL_ENABLE_Msk;
SysTick->VAL = 0x00;
}
void DELAY_ms(unsigned int n)
{
unsigned int Temp;
SysTick->LOAD = n*Base_ms;
SysTick->VAL = 0x00;
SysTick->CTRL|= SysTick_CTRL_ENABLE_Msk;
do
{
Temp = SysTick->CTRL;
}while((Temp&0x01)&&!(Temp&(1<<16)));
SysTick->CTRL &= ~SysTick_CTRL_ENABLE_Msk;
SysTick->VAL = 0x00;
}
以上是关于延时Delay的主要内容,如果未能解决你的问题,请参考以下文章