新手入门
- 积分
- 6
- 金钱
- 6
- 注册时间
- 2020-4-7
- 在线时间
- 3 小时
|
1金钱
我的程序TIM1和TIM4同时使用,但是老是停在TIM1中,TIM4没法使用,是不是中断优先级问题,如果是优先级问题,把TIM4设置高的话,TIM1会不会也用不了,新手,请多包含
void Timer1_Init(void)
{
TIM1_TimeBaseInit(16,TIM1_COUNTERMODE_UP,1000,0);
TIM1_ARRPreloadConfig(ENABLE);
TIM1_ITConfig(TIM1_IT_UPDATE , ENABLE);
TIM1_Cmd(ENABLE);
}
void TimingDelay_Decrement(void)
{
if (TimingDelay != 0x00)
{
TimingDelay--;
}
}
void delay_ms( u32 nTime)
{
TimingDelay = nTime;
while(TimingDelay != 0);
}
void Timer4_Init(u8 Count)
{
TIM4_DeInit();
TIM4_TimeBaseInit(TIM4_PRESCALER_128,Count);
TIM4_ITConfig(TIM4_IT_UPDATE, ENABLE);
TIM4_Cmd(ENABLE);
}
INTERRUPT_HANDLER(TIM1_UPD_OVF_TRG_BRK_IRQHandler, 11)
{
TimingDelay_Decrement();
i++;
TIM1_ClearITPendingBit(TIM1_IT_UPDATE);
// Conversion_Value = ADC2_GetConversionValue();
// Delay(0xffff);
// Delay(0xffff);
// ADC_Value(Conversion_Value);
// TIM1_ClearITPendingBit(TIM1_IT_UPDATE);
}
INTERRUPT_HANDLER(TIM4_UPD_OVF_IRQHandler, 23)
{
i++;
if(i==490) //16M
{
LED_Toggle(LED1|LED2|LED3);
i=0;
}
TIM4_ClearITPendingBit(TIM4_IT_UPDATE);
}
void main(void)
{
/*内部高速时钟16M为主时钟*/
CLK_HSIPrescalerConfig(CLK_PRESCALER_HSIDIV1);
LED_Init(LED1|LED2|LED3);
Timer4_Init(0xFF);
KEY_Init();
ADC_Init();
#if CONVERSIONMODE ==CONVERSIONMODE_CONTINUOUS
Timer1_Init();
#endif
Delay(0xffff);
Delay(0xffff);
Delay(0xffff);
while (1)
{
}
}
|
|