问题是这样的,自己写了输出捕获的配置,但是实现不了红外的功能,然后把这部分的程序用了原子的,功能就实现了(程序会在最后贴出来)。而我写的与原子写的程序区别在于定义的变量名字不一样,然后同一个结构的配置的顺序不一样。这是什么原因导致程序会实现不了功能,难道变量名和配置的顺序有问题(即哪个管脚,输出输入模式这种顺序,并非逻辑上的顺序),注释掉的程序为自己写的,没注释掉的为原子的源程序
void rm_init(void)
{
// GPIO_InitTypeDef GPIO_InitString;
// TIM_TimeBaseInitTypeDef TIM_TimeBaseInitString;
// TIM_ICInitTypeDef TIM_ICInitString;
// NVIC_InitTypeDef NVIC_InitString;
//
// RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);//使能GPIOA时钟
// RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1, ENABLE); //TIM1时钟使能
//
// GPIO_InitString.GPIO_Mode =GPIO_Mode_AF;
// GPIO_InitString.GPIO_OType =GPIO_OType_PP;
// GPIO_InitString.GPIO_Pin =GPIO_Pin_8;
// GPIO_InitString.GPIO_PuPd =GPIO_PuPd_UP;
// GPIO_InitString.GPIO_Speed =GPIO_Speed_100MHz;
// GPIO_Init(GPIOA,&GPIO_InitString);
//
// GPIO_PinAFConfig(GPIOA,GPIO_PinSource8,GPIO_AF_TIM1);
// TIM_TimeBaseInitString.TIM_ClockDivision =TIM_CKD_DIV1;
// TIM_TimeBaseInitString.TIM_CounterMode =TIM_CounterMode_Up;
// TIM_TimeBaseInitString.TIM_Period =167;
// TIM_TimeBaseInitString.TIM_Prescaler =10000;
// TIM_TimeBaseInit(TIM1,&TIM_TimeBaseInitString);
// TIM_ICInitString.TIM_Channel =TIM_Channel_1;
// TIM_ICInitString.TIM_ICFilter =0x03;
// TIM_ICInitString.TIM_ICPolarity =TIM_ICPolarity_Rising;
// TIM_ICInitString.TIM_ICPrescaler =TIM_ICPSC_DIV1;
// TIM_ICInitString.TIM_ICSelection =TIM_ICSelection_DirectTI;
// TIM_ICInit(TIM1,&TIM_ICInitString);
//
// TIM_ITConfig(TIM1,TIM_IT_Update|TIM_IT_CC1,ENABLE);
// TIM_Cmd(TIM1,ENABLE);
//
//
// NVIC_InitString.NVIC_IRQChannel =TIM1_CC_IRQn;//TIM1_UP_TIM10_IRQn
// NVIC_InitString.NVIC_IRQChannelPreemptionPriority =1;
// NVIC_InitString.NVIC_IRQChannelSubPriority =3;
// NVIC_InitString.NVIC_IRQChannelCmd =ENABLE;
// NVIC_Init(&NVIC_InitString);
// NVIC_InitString.NVIC_IRQChannel =TIM1_UP_TIM10_IRQn; //TIM1_UP_TIM10_IRQn
// NVIC_InitString.NVIC_IRQChannelPreemptionPriority =1;
// NVIC_InitString.NVIC_IRQChannelSubPriority =2;
// NVIC_InitString.NVIC_IRQChannelCmd =ENABLE;
// NVIC_Init(&NVIC_InitString);
GPIO_InitTypeDef GPIO_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
TIM_ICInitTypeDef TIM1_ICInitStructure;
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);//使能GPIOA时钟
RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1, ENABLE);//TIM1时钟使能
//GPIOA8 复用功能,上拉
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;//复用功能
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;//推挽输出
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;//100MHz
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;//上拉
GPIO_Init(GPIOA, &GPIO_InitStructure);//初始化
GPIO_PinAFConfig(GPIOA,GPIO_PinSource8,GPIO_AF_TIM1); //GPIOA8复用为TIM1
TIM_TimeBaseStructure.TIM_Prescaler=167; ////预分频器,1M的计数频率,1us加1.
TIM_TimeBaseStructure.TIM_CounterMode=TIM_CounterMode_Up; //向上计数模式
TIM_TimeBaseStructure.TIM_Period=10000; //设定计数器自动重装值 最大10ms溢出
TIM_TimeBaseStructure.TIM_ClockDivision=TIM_CKD_DIV1;
TIM_TimeBaseInit(TIM1,&TIM_TimeBaseStructure);
//初始化TIM2输入捕获参数
TIM1_ICInitStructure.TIM_Channel = TIM_Channel_1; //CC1S=01 选择输入端 IC1映射到TI1上
TIM1_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_Rising; //上升沿捕获
TIM1_ICInitStructure.TIM_ICSelection = TIM_ICSelection_DirectTI; //映射到TI1上
TIM1_ICInitStructure.TIM_ICPrescaler = TIM_ICPSC_DIV1; //配置输入分频,不分频
TIM1_ICInitStructure.TIM_ICFilter = 0x03;//IC1F=0003 8个定时器时钟周期滤波
TIM_ICInit(TIM1, &TIM1_ICInitStructure);//初始化定时器2输入捕获通道
TIM_ITConfig(TIM1,TIM_IT_Update|TIM_IT_CC1,ENABLE);//允许更新中断 ,允许CC1IE捕获中断
TIM_Cmd(TIM1,ENABLE ); //使能定时器1
NVIC_InitStructure.NVIC_IRQChannel = TIM1_CC_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=1;//抢占优先级1
NVIC_InitStructure.NVIC_IRQChannelSubPriority =3; //子优先级3
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //IRQ通道使能
NVIC_Init(&NVIC_InitStructure); //初始化NVIC寄存器
NVIC_InitStructure.NVIC_IRQChannel = TIM1_UP_TIM10_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=1;//抢占优先级3
NVIC_InitStructure.NVIC_IRQChannelSubPriority =2; //子优先级2
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //IRQ通道使能
NVIC_Init(&NVIC_InitStructure); //初始化NVIC寄存器
}
一周热门 更多>