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。 |
TIM1_CCER2 |= ~0x02;//上升沿或者高电平触发
TIM1_CCER2 |= 0x01; //捕获使能
第一句是配置上升沿中断,第二句是配置捕捉使能;现在就是能产生中断,但是TIM1_CCR3寄存器中没有值,不知道怎么回事,能帮我看下吗,谢谢
第一句是配置上升沿中断,第二句是配置捕捉使能;现在就是能产生中断,但是TIM1_CCR3寄存器中没有值,不知道怎么回事,能帮我看下吗,谢谢!
评分
查看全部评分
TIM1_CR1 = 00; //计数器向上计数
TIM1_PSCRH = 0x00; //设置时钟分频 2M/2=1MHz---1us
TIM1_PSCRL = 0x01;
TIM1_ARRH = 0x27; //0x270F=9999
TIM1_ARRL = 0x0F; //ARR自动装载值
TIM1_CNTRH = 0x00; //初值
TIM1_CNTRL = 0x00;
TIM1_CCMR2 |= 0x01; //TIM1_CCMR1_CC1S
TIM1_CCER1 |= ~0x20; //上升沿或者高电平触发//TIM1_CCER1_CC1P
TIM1_SR1 &=~(0x04);
TIM1_IER |= 0x05; //允许捕获中断
TIM1_CCER1 |= 0x10;
TIM1_IER |= 0x01; //允许捕获中断
TIM1_CR1 |= 0x05; //开启定时器
现在捕捉产生中断,但是每次中断TIM1_CCR2数据不变化,都是一个值,这个是什么原因,而且值的时间也不对?