標(biāo)題: STM32 TIM6定時器中斷函數(shù) [打印本頁]

作者: haungqiang    時間: 2017-11-10 11:43
標(biāo)題: STM32 TIM6定時器中斷函數(shù)
本人STM32初學(xué)者,此程序在正點原子Mini平臺上運行。
測試過可以使用,不對語句進(jìn)行解釋,只用于初步學(xué)習(xí)。
主函數(shù):
#include "led.h"
#include "delay.h"
#include "sys.h"
#include "tim1.h"
int main (void)
{
delay_init()
NVIC_PriorityGroupConfig( NVIC_PriorityGroup_2)
LED_Init();
TIM7_Init(4999,7199);
while(1)
{
delay_ms(1000);
LED0=!LED0;
}
}
定時器函數(shù);
#include "tim1.h"
#include "led.h"



void TIM7_Init(u16 arr,u16 psc)
{
        TIM_TimeBaseInitTypeDef TIM_TimeBaseInitStruct;
        NVIC_InitTypeDef NVIC_InitStruct;
       
  //RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE);
        RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM7,ENABLE);
//¶¨ê±Æ÷1μÄéèÖ㨶¨ê±Æ÷1oí2Ö»óDÏòéϼÆêyģ꽣©
        TIM_TimeBaseInitStruct.TIM_Period=arr;
        TIM_TimeBaseInitStruct.TIM_Prescaler=psc;//Ô¤·ÖÆμÏμêy
        TIM_TimeBaseInitStruct.TIM_CounterMode=TIM_CounterMode_Up;
        TIM_TimeBaseInitStruct.TIM_ClockDivision=TIM_CKD_DIV1;
        TIM_TimeBaseInit(TIM7,&TIM_TimeBaseInitStruct);       
        TIM_ITConfig(TIM7,TIM_IT_Update,ENABLE);//ÔêDí¸üDÂÖD¶Ï
       
        NVIC_InitStruct.NVIC_IRQChannel=TIM7_IRQn;
        NVIC_InitStruct.NVIC_IRQChannelPreemptionPriority=0;
        NVIC_InitStruct.NVIC_IRQChannelSubPriority=3;
        NVIC_InitStruct.NVIC_IRQChannelCmd=ENABLE;
        NVIC_Init(&NVIC_InitStruct);       
        TIM_Cmd(TIM7,ENABLE);         
}
void TIM7_IRQHandler()
{
if(TIM_GetITStatus(TIM7,TIM_IT_Update)!=RESET)
{

                TIM_ClearITPendingBit(TIM7, TIM_IT_Update);
          LED=!LED;
}
}


       







歡迎光臨 (http://www.torrancerestoration.com/bbs/) Powered by Discuz! X3.1