中级会员
 
- 积分
- 253
- 金钱
- 253
- 注册时间
- 2015-4-29
- 在线时间
- 38 小时
|

楼主 |
发表于 2016-5-27 09:42:34
|
显示全部楼层
void TIM3_Int_Init(u16 arr,u16 psc)
{
TIM_TimeBaseInitTypeDef TIM_TimeBaseInitStructure;
GPIO_InitTypeDef GPIO_InitStructure;
// TIM_ICInitTypeDef TIM_ICInitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB1Periph_TIM3,ENABLE); ///使能TIM3时钟
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);//使能GPIOA时钟
//PA0配置
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;//复用功能
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;//100MHz
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; //推完输出
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_DOWN;//上拉
GPIO_Init(GPIOA, &GPIO_InitStructure);//初始化
GPIO_PinAFConfig(GPIOA,GPIO_PinSource6,GPIO_AF_TIM3); //PA0复用位定时器5
TIM_TimeBaseInitStructure.TIM_Period = arr; //自动重装载值
TIM_TimeBaseInitStructure.TIM_Prescaler=psc; //定时器分频
TIM_TimeBaseInitStructure.TIM_CounterMode=TIM_CounterMode_Up; //向上计数模式
TIM_TimeBaseInitStructure.TIM_ClockDivision=TIM_CKD_DIV1;
TIM_TimeBaseInit(TIM3,&TIM_TimeBaseInitStructure);//初始化TIM3
TIM_TIxExternalClockConfig(TIM3, TIM_TIxExternalCLK1Source_TI1, TIM_ICPolarity_Rising, 0);
TIM_CounterModeConfig(TIM3,TIM_CounterMode_Up);//计数模式
// TIM_TIxExternalClockConfig(TIM5,TIM_TIxExternalCLK1Source_TI2,TIM_ICPolarity_Rising,0);
// TIM_ETRClockMode1Config(TIM2,TIM_ExtTRGPSC_OFF,TIM_ExtTRGPolarity_NonInverted,0);
TIM_ITConfig(TIM3,TIM_IT_CC2|TIM_IT_Update,ENABLE); //允许更新中断
// TIM_SetAutoreload(TIM2,9);
TIM_SetCounter(TIM3,0);//设置计数初值
TIM_Cmd(TIM3,ENABLE); //使能定时器3
NVIC_InitStructure.NVIC_IRQChannel=TIM3_IRQn; //
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=0x01; //
NVIC_InitStructure.NVIC_IRQChannelSubPriority=0x02; //
NVIC_InitStructure.NVIC_IRQChannelCmd=ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
不知道怎样设置对不对,麻烦大神帮我看一下,原子哥哥也来帮我看一下吧 |
|