STM32定时器(一):通用定时器实现定时并产生着中断

void Tim3init(void)
{
    TIM_TimeBaseInitTypeDef t;
    NVIC_InitTypeDef n;
    RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE); //ê±?óê1?ü

    t. TIM_Period=10000-1;
    t. TIM_Prescaler=7199;
    t. TIM_CounterMode=TIM_CounterMode_Up;
    t. TIM_ClockDivision=TIM_CKD_DIV1;
    t. TIM_RepetitionCounter=0;  

    TIM_TimeBaseInit(TIM3,&t);

    TIM_ITConfig(TIM3,TIM_IT_Update,ENABLE);


    n. NVIC_IRQChannel=TIM3_IRQn;  
    n. NVIC_IRQChannelPreemptionPriority=1;
    n. NVIC_IRQChannelSubPriority=1;        
    n. NVIC_IRQChannelCmd=ENABLE;        
    NVIC_Init(&n);
    TIM_Cmd(TIM3,ENABLE);     

}

void TIM3_IRQHandler(void)
{
   if(TIM_GetITStatus(TIM3,TIM_IT_Update)!=RESET)
   {

    GPIO_WriteBit(GPIOB,GPIO_Pin_5,(BitAction)(!(GPIOB->ODR&GPIO_Pin_5)));
    TIM_ClearITPendingBit(TIM3,TIM_IT_Update);
   }

}
上一篇:FreeModbus移植记录(一)野火指南者+Keil+FreeModbus 的Modbus RTU从站


下一篇:史上最强Android保活思路:深入剖析腾讯TIM的进程永生技术