初中生
最后登录1970-1-1
在线时间 小时
注册时间2016-3-4
|
楼主 |
发表于 2016-3-5 14:54:34
|
显示全部楼层
void GPIO_Configure()
{
GPIO_InitTypeDef GPIO_InitTyfff;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB,ENABLE);
GPIO_InitTyfff.GPIO_Mode=GPIO_Mode_IN_FLOATING;
GPIO_InitTyfff.GPIO_Pin=GPIO_Pin_1;
GPIO_Init(GPIOB,&GPIO_InitTyfff); //通道4的io口设置
}
void TIM_Configure()
{
TIM_ICInitTypeDef TIM_ICInitSructure;
TIM_TimeBaseInitTypeDef TIM_TimeBaseSructure;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3,ENABLE);
TIM_TimeBaseSructure.TIM_ClockDivision=0;
TIM_TimeBaseSructure.TIM_CounterMode=TIM_CounterMode_Up;
TIM_TimeBaseSructure.TIM_Period=0xffff;
TIM_TimeBaseSructure.TIM_Prescaler=71;
TIM_TimeBaseInit(TIM3,&TIM_TimeBaseSructure);
TIM_ICInitSructure.TIM_Channel=TIM_Channel_4;
TIM_ICInitSructure.TIM_ICFilter=0x0;
TIM_ICInitSructure.TIM_ICPolarity=TIM_ICPolarity_Rising;
TIM_ICInitSructure.TIM_ICPrescaler=TIM_ICPSC_DIV1;
TIM_ICInitSructure.TIM_ICSelection=TIM_ICSelection_DirectTI;
TIM_ICInit(TIM3,&TIM_ICInitSructure);
//TIM_SelectInputTrigger(TIM3,TIM_TS_TI1FP1);
//TIM_SelectSlaveMode(TIM3,TIM_SlaveMode_Reset);
//TIM_SelectMasterSlaveMode(TIM3,TIM_MasterSlaveMode_Enable);
TIM_Cmd(TIM3,ENABLE);
TIM_ITConfig(TIM3,TIM_IT_CC4,ENABLE);
}
void NVIC_Configure()
{
NVIC_InitTypeDef NVIC_Inijj;
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_4);
NVIC_Inijj.NVIC_IRQChannel=TIM3_IRQn;
NVIC_Inijj.NVIC_IRQChannelCmd=ENABLE;
NVIC_Inijj.NVIC_IRQChannelPreemptionPriority=0;
NVIC_Inijj.NVIC_IRQChannelSubPriority=0;
NVIC_Init(&NVIC_Inijj);
}
void TIM3_IRQHandler(void)
{
if(TIM_GetITStatus(TIM3,TIM_IT_CC4)!=0)
{
TIM_ClearITPendingBit(TIM3,TIM_IT_CC4);
Read=TIM_GetCapture4(TIM3)*2;
Frequence=1000000/Read;
}
}
我屏蔽了那三句,可是数据还是不对!!!
上面是引脚配置,中断配置,麻烦了!!!
|
|