RCC- gt;APB2ENR = 0x0845; //使能TIM1和GPIOA/E和AFIO时钟}
GPIOA- gt;CRH = 0x0B; //PA8,9配置为复用推挽输出,50MHz
TIM1- gt;ARR = 0xffff; //ARR为最大值,使用CCR1和CCR2的比较匹配事件来产生中断
TIM1- gt;DIER = 0x06; //使能中断CC1IE和CC2IE
TIM1- gt;CCMR1 = 0x3030; //CH1和CH2都是输出比较模式(翻转)
TIM1- gt;BDTR = 0x8000; //使能MOE主输出
TIM1- gt;CCER |= TIM_CCER_CC1E; //使能CC1E输出
TIM1- gt;CR1 |= TIM_CR1_CEN; //使能定时器
CCR_Acc_x = 562;
CCR_Acc_y = 18000;
TIM1- gt;CCR1 = CCR_Acc_x;
TIM1- gt;CCR2 = CCR_Acc_y;
TIM1- gt;CCR3 = 0xffff;
TIM1- gt;CCR4 = 0xffff;
NVIC_SetPriorityGrouping(4); //3 bits preemption
NVIC_SetPriority(TIM1_CC_IRQn, 0); //highest
NVIC_EnableIRQ(TIM1_CC_IRQn);
DBGMCU- gt;CR |= DBGMCU_TIM1_STOP;
while(1)
{
}
TIM1_SR_mask = TIM1- gt;SR;
if (TIM1_SR_mask amp; TIM_SR_CC1IF) //CC1IF
{
TIM1- gt;SR = ~TIM_SR_CC1IF;TIM1- gt;CCR1 = TIM1- gt;CCR1 + CCR_Acc_x;
}
if (TIM1_SR_mask amp; TIM_SR_CC2IF) //CC2IF
{
TIM1- gt;SR = ~TIM_SR_CC2IF;
}
TIM1_SR_mask = TIM1- gt;SR;
if (TIM1_SR_mask amp; TIM_SR_CC1IF) //CC1IF
{
NVIC_SetPendingIRQ(TIM1_CC_IRQn);
}
if (TIM1_SR_mask amp; TIM_SR_CC2IF) //CC2IF
{
NVIC_SetPendingIRQ(TIM1_CC_IRQn);
}}//exit breakpoint here
更多回帖