首页 > 其他 > 详细

STM32 之 SysTick

时间:2016-01-25 14:36:15      阅读:302      评论:0      收藏:0      [点我收藏+]

基于中断方式延时效果

1.SysTick配置

void SysTick_Init(void)
{
/* SystemCoreClock / 1000 1ms
* SystemCoreClock / 100000    10us
* SystemCoreClock / 1000000 1us
*/
while(SysTick_Config( SystemCoreClock / 1000));    //
}

 

2.中断配置

void NVIC_Configuration(void)
{
  NVIC_InitTypeDef NVIC_InitStructure;

    /* Configure one bit for preemption priority */
    NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);           //
      
    /* Enable the EXTI0_IRQn Interrupt */
    NVIC_InitStructure.NVIC_IRQChannel = SysTick_IRQn;        //
    NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; //
    NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;        //
    NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;            //
    NVIC_Init(&NVIC_InitStructure); 
}

3.中断函数入口

void SysTick_Handler(void)
{
  if (TimingDelay != 0x00)
  { 
    TimingDelay--;
  }
  
  
}

4. 延时函数使用

void Delay(u32 nTime)
{ 
  TimingDelay = nTime;

  while(TimingDelay != 0);
}

5.整体调用

int main(void)
{        
     SysTick_Init();
     LED_GPIO_Config();
     NVIC_Configuration();    
    while (1)
    {
         Delay(1000);//        
     /*  ~~~~~~~~~*/    
    }
}

 

STM32 之 SysTick

原文:http://www.cnblogs.com/yeshuimaowei/p/5157163.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!