/*初始化时钟*/
void Init_SysTick(void)
{
/* Disable SysTick Counter */
SysTick_CounterCmd(SysTick_Counter_Disable);
/* Disable the SysTick Interrupt */
SysTick_ITConfig(DISABLE);
/* Configure HCLK clock as SysTick clock source */
SysTick_CLKSourceConfig(SysTick_CLKSource_HCLK_Div8);
/* SysTick interrupt each 1000 Hz with HCLK equal to 72MHz */
SysTick_SetReload(9000);
/* Enable the SysTick Interrupt */
SysTick_ITConfig(ENABLE);
}
/*延时1ms函数*/
__IO uint32_t TimingDelay;
void delay_ms(__IO uint32_t nTime)
{
/* Enable the SysTick Counter */
SysTick_CounterCmd(SysTick_Counter_Enable);
TimingDelay = nTime;
while(TimingDelay != 0);
/* Disable SysTick Counter */
SysTick_CounterCmd(SysTick_Counter_Disable);
/* Clear SysTick Counter */
SysTick_CounterCmd(SysTick_Counter_Clear);
}
/*stm32f10x_it.c中的void SysTick_Handler(void)函数改为*/
extern __IO uint32_t TimingDelay;
void SysTick_Handler(void)
{
if (TimingDelay != 0x00)
{
TimingDelay--;
}
}
/*用法,延时1秒*/
delay_ms(1000);
/*初始化时钟*/
void Init_SysTick(void)
{
if(SysTick_Config(SystemCoreClock / 1000)) //注意:3.5库中 SystemFrequency 被 SystemCoreClock 取代。
while(1);
}
/*延时1ms函数*/
__IO uint32_t TimingDelay;
void delay_ms(__IO uint32_t nTime)
{
TimingDelay = nTime;
while(TimingDelay != 0);
}
/*stm32f10x_it.c中的void SysTick_Handler(void)函数改为*/
extern __IO uint32_t TimingDelay;
void SysTick_Handler(void)
{
if (TimingDelay != 0x00)
{
TimingDelay--;
}
}
/*用法,延时1秒*/
delay_ms(1000);
上一篇:stm32 - keil中启动文件的选择和固件库宏定义
下一篇:关于stm32启动文件的选择
推荐阅读最新更新时间:2024-03-16 15:13