學習正點原子Mini板,進行到定時器內容時,卡主了好久,自己沒頭緒找不出哪里出問題了,特此發帖望有技之人指導一下。
程序描述:通過基本定時器7定時500ms吃產生中斷,使led翻轉。
#include "led.h"
#include "delay.h"
#include "sys.h"
#include "tim1.h"
int main (void)
{
delay_init();//3õê¼»ˉÑóê±oˉêy
NVIC_PriorityGroupConfig( NVIC_PriorityGroup_2);//éèÖÃÖD¶ÏóÅÏè¼¶·Ö×é
LED_Init();//3õê¼»ˉledoˉêy
TIM7_Init(4999,7199);
while(1);
}
#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);
//定時器中斷配置
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(TIM1,&TIM_TimeBaseInitStruct);
TIM_ITConfig(TIM7,TIM_IT_Update,ENABLE);//使能定時器更新
TIM_Cmd(TIM7,ENABLE);//使能定時器
NVIC_InitStruct.NVIC_IRQChannel=TIM7_IRQn;
NVIC_InitStruct.NVIC_IRQChannelPreemptionPriority=0;
NVIC_InitStruct.NVIC_IRQChannelSubPriority=0;
NVIC_InitStruct.NVIC_IRQChannelCmd=ENABLE;
NVIC_Init(&NVIC_InitStruct);
}
定時器7中斷使led翻轉狀態
void TIM7_IRQHandler()
{
if(TIM_GetITStatus(TIM7,TIM_IT_Update)!=SET)
{
TIM_ClearITPendingBit(TIM1, TIM_IT_Update);
LED=!LED;
}
}
|