• 定时器中断实验


     int main(void)
     {    
        NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2,);
        LED_Init();
        delay_init();
         TIM3_Int_Init(4999,7199);//500ms
         while(1)
        {
            LED1=!LED1;
            TIM_ClearITPendingBit(TIM3,TIM_IT_Update);
         }
     }
    main
    timer.c
    #include "timer.h"
    #include "led.h"
    void TIM3_Int_Init(u16 arr,u16 psc)  //定时器初始化
    {
        TIM_TimeBaseInitTypeDef TIM_TimeBaseInitStrue;
        
        NVIC_InitTypeDef NVIC_InitStructure;
        
        
        RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3,ENABLE);
        TIM_TimeBaseInitStrue.TIM_Period=arr;
        TIM_TimeBaseInitStrue.TIM_Prescaler=psc;
        TIM_TimeBaseInitStrue.TIM_CounterMode=TIM_CounterMode_Up;
        TIM_TimeBaseInitStrue.TIM_ClockDivision=TIM_CKD_DIV1;
        TIM_TimeBaseInit(TIM3,&TIM_TimeBaseInitStrue);
        
        TIM_ITConfig(TIM3,TIM_IT_Update,ENABLE);//使能定时器更新中断
        NVIC_InitStructure.NVIC_IRQChannel=TIM3_IRQn;//TIM3中断
        NVIC_InitStructure.NVIC_IRQChannelCmd=ENABLE;//IRQ通道被使能
        NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=0;//先抢占优先级设置为0
        NVIC_InitStructure.NVIC_IRQChannelSubPriority=3;//从优先级3级
        NVIC_Init(&NVIC_InitStructure);//初始化NVIC寄存器
        
        TIM_Cmd(TIM3,ENABLE);//定时器3使能
    }    
    void     TIM3_IRQHandler(void)
    {
        if(TIM_GetITStatus(TIM3,TIM_IT_Update)!=RESET)
        {
            LED1=!LED1;
            TIM_ClearITPendingBit(TIM3,TIM_IT_Update);
        }    
    }    
  • 相关阅读:
    2. 逻辑运算
    1. 条件
    6. 可变不可变类型
    5. 基本运算符
    4. 与用户交互
    12 .命名的EIGRP和EIGRP v6
    11. EIGRP路由SIA
    Redis 快速入门 -- Redis 快速入门(2)
    Redis 快速入门 -- Redis教程(1)
    Redis 百度百科
  • 原文地址:https://www.cnblogs.com/alantechnique/p/5621487.html
Copyright © 2020-2023  润新知