void delay_ms(unsigned int ms)
{
SysTick->LOAD = 50000000/1000-1; // Count from 255 to 0 (256 cycles) 载入计数值 定时器从这个值开始计数
SysTick->VAL = 0; // Clear current value as well as count flag 清空计数值到达0后的标记
SysTick->CTRL = 5; // Enable SysTick timer with processor clock 使能26MHz的系统定时器
while(ms--)
{
while ((SysTick->CTRL & 0x00010000)==0);// Wait until count flag is set 等待
}
SysTick->CTRL = 0; // Disable SysTick 关闭系统定时器
}
void delay_us(unsigned int us)
{
SysTick->LOAD = 50000000/1000/1000-1; // Count from 255 to 0 (256 cycles) 载入计数值 定时器从这个值开始计数
SysTick->VAL = 0; // Clear current value as well as count flag 清空计数值到达0后的标记
SysTick->CTRL = 5; // Enable SysTick timer with processor clock 使能26MHz的系统定时器
while(us--)
{
while ((SysTick->CTRL & 0x00010000)==0);// Wait until count flag is set 等待
}
SysTick->CTRL = 0; // Disable SysTick 关闭系统定时器
}
|