用的是103F的片子,想把TIM1设置成翻转输出比较模式,但端口不会发生翻转
配置程序如下:
GPIO_Init(GPIOC, GPIO_PIN_6, GPIO_MODE_OUT_PP_HIGH_FAST);
TIM1->CR1 &= 0xFE; // stop TIM1
TIM1->PSCRH = 0;
TIM1->PSCRL = 0;
TIM1->CR1 = 0;
TIM1->CR2 = 0;
TIM1->EGR = 0x20;
TIM1->CNTRH = 0;
TIM1->CNTRL = 0;
TIM1->CCR1H = 0x1f;
TIM1->CCR1L = 0xff;
TIM1->IER = 2;
TIM1->CCMR1 = 0x30; // 输出,禁止预装载,比较匹配翻转
TIM1->CCER1 = 0x01; // 0x03;
TIM1->CCER2 = 0;
//TIM1->OISR = 0x01;
TIM1->BKR = 0x80;
TIM1->CR1 |= 0x01;
中断程序:
@interrupt void Timer_PWM_IRQ(void)
{
u8 tempirq;
TIM1->CR1 &= 0xFE; // stop TIM1
if(TIM1->SR1 & 0x02)
{
TIM1->CNTRH = 0;
TIM1->CNTRL = 0;
TIM1->SR1 &= (u8)(~0x02);
}
TIM1->CR1 |= 0x01;
}
会发生中断,但输出口PC6一直是高电平,不会发生翻转
请高手指点下.谢谢! |