初级会员
- 积分
- 52
- 金钱
- 52
- 注册时间
- 2014-5-27
- 在线时间
- 2 小时
|
楼主 |
发表于 2014-11-6 09:20:19
|
显示全部楼层
void TIM3_Int_Init(u16 arr,u16 psc)
{
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
NVIC_InitTypeDef NVIC_InitStructure;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE); //?±??????
//?¨?±?÷TIM3??????
TIM_TimeBaseStructure.TIM_Period = arr; //?è???????????ü??????×°????????×?????×°???????÷????????
TIM_TimeBaseStructure.TIM_Prescaler =psc; //?è??????×÷??TIMx?±?????????????¤·?????
TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1; //?è???±??·???:TDTS = Tck_tim
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; //TIM?ò??????????
TIM_TimeBaseInit(TIM3, &TIM_TimeBaseStructure); //?ù?????¨????????????TIMx???±???ù??????
TIM_ITConfig(TIM3,TIM_IT_Update,ENABLE ); //???????¨??TIM3????,???í?ü??????
//??????????NVIC?è??
NVIC_InitStructure.NVIC_IRQChannel = TIM3_IRQn; //TIM3????
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; //??????????0??
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 3; //????????3??
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //IRQ?¨??±?????
NVIC_Init(&NVIC_InitStructure); //??????NVIC?????÷
TIM_Cmd(TIM3, ENABLE); //????TIMx
}
//?¨?±?÷3????·??????ò
void TIM3_IRQHandler(void) //TIM3????
{
if (TIM_GetITStatus(TIM3, TIM_IT_Update) != RESET) //?ì?éTIM3?ü??????·??ú??·?
{
TIM_ClearITPendingBit(TIM3, TIM_IT_Update ); //????TIMx?ü??????±ê??
LED1=!LED1;
}
} |
|