|
學(xué)習(xí)正點(diǎn)原子Mini板,進(jìn)行到定時(shí)器內(nèi)容時(shí),卡主了好久,自己沒(méi)頭緒找不出哪里出問(wèn)題了,特此發(fā)帖望有技之人指導(dǎo)一下。
程序描述:通過(guò)基本定時(shí)器7定時(shí)500ms吃產(chǎn)生中斷,使led翻轉(zhuǎn)。
#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);
//定時(shí)器中斷配置
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);//使能定時(shí)器更新
TIM_Cmd(TIM7,ENABLE);//使能定時(shí)器
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);
}
定時(shí)器7中斷使led翻轉(zhuǎn)狀態(tài)
void TIM7_IRQHandler()
{
if(TIM_GetITStatus(TIM7,TIM_IT_Update)!=SET)
{
TIM_ClearITPendingBit(TIM1, TIM_IT_Update);
LED=!LED;
}
}
|
|