|
楼主 |
发表于 2011-8-12 19:45:50
|
显示全部楼层
关于定时器相关的代码不多,就是定时器设置,和中断处理
void TIM_Configuration(void)
{
TIM_ICInitTypeDef TIM_ICInitStructure;
//TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
//TIM_OCInitTypeDef TIM_OCInitStructure;
TIM_ICInitStructure.TIM_Channel = TIM_Channel_2;
TIM_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_Rising;
TIM_ICInitStructure.TIM_ICSelection = TIM_ICSelection_DirectTI;
TIM_ICInitStructure.TIM_ICPrescaler = TIM_ICPSC_DIV1;
TIM_ICInitStructure.TIM_ICFilter = 0x0;
TIM_ICInit(TIM2, &TIM_ICInitStructure);
TIM_PWMIConfig(TIM2, &TIM_ICInitStructure);
TIM_SelectInputTrigger(TIM2, TIM_TS_TI2FP2); /* Select the TIM2 Input Trigger: TI2FP2 */
TIM_SelectSlaveMode(TIM2, TIM_SlaveMode_Reset); /* Select the slave Mode: Reset Mode */
TIM_SelectMasterSlaveMode(TIM2, TIM_MasterSlaveMode_Enable); /* Enable the Master/Slave Mode */
TIM_Cmd(TIM2, ENABLE); /* TIM enable counter */
TIM_ITConfig(TIM2, TIM_IT_CC2, ENABLE); /* Enable the CC2 Interrupt Request */
TIM_ICInitStructure.TIM_Channel = TIM_Channel_1;
TIM_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_Rising;
TIM_ICInitStructure.TIM_ICSelection = TIM_ICSelection_DirectTI;
TIM_ICInitStructure.TIM_ICPrescaler = TIM_ICPSC_DIV1;
TIM_ICInitStructure.TIM_ICFilter = 0x0;
TIM_ICInit(TIM3, &TIM_ICInitStructure);
TIM_PWMIConfig(TIM3, &TIM_ICInitStructure);
TIM_SelectInputTrigger(TIM3, TIM_TS_TI1FP1); /* Select the TIM2 Input Trigger: TI2FP2 */
TIM_SelectSlaveMode(TIM3, TIM_SlaveMode_Reset); /* Select the slave Mode: Reset Mode */
TIM_SelectMasterSlaveMode(TIM3, TIM_MasterSlaveMode_Enable); /* Enable the Master/Slave Mode */
TIM_Cmd(TIM3, ENABLE); /* TIM enable counter */
TIM_ITConfig(TIM3, TIM_IT_CC1, ENABLE); /* Enable the CC2 Interrupt Request */
}
下面是中断处理
void TIM2_IRQ(void)
{
PlusCounter ++;
TIM_ClearITPendingBit(TIM2, TIM_IT_CC2); /* Clear TIM2 Capture compare interrupt pending bit */
} |
|