void TIM1_Init(void)
{
TIM1_IER = 0x00; //禁止中断
TIM1_EGR = 0x01; //允许产生更新标志
//TIM1_PSCR =0x08; //设置时钟分频 2M/2=1MHz---1us
TIM1_PSCRH = 0x00;
TIM1_PSCRL = 0x01;
TIM1_ARRH = 0x27; //0x270F=9999
TIM1_ARRL = 0x0F; //ARR自动装载值
TIM1_CNTRH = 0x00; //初值
TIM1_CNTRL = 0x00;
TIM1_CCMR3 |= 0x01;
TIM1_CCER2 |= ~0x02;//上升沿或者高电平触发
TIM1_CCER2 |= 0x01; //捕获使能
TIM1_IER |= 0x08; //允许捕获中断
TIM1_SMCR = 0x54; //复位触发模式
TIM1_IER |= 0x01; //允许中断
TIM1_CR1 |= 0x81; //开启定时器
},定时器中断正常,捕捉不能产生中断,用的是TIM1_CH3N通道,单片机型号是STM8S003K3。 |