如题:STM8S系列单片机,TIM4作为基本的定时器,但是当中断打开以后,运行一段时间直接进入
@far @interrupt void NonHandledInterrupt (void),不知道为啥,TIM4初始化:
void TIM4_Init(void)
{
CLK->PCKENR1 |= 0x10; //enable TIM4;
TIM4->CR1 = 0x00 ; /*!< control register 1 */
TIM4->IER = 0x01; /*!< interrupt enable register */ //enable update interrupt
TIM4->SR1 = 0x00; /*!< status register 1 */
TIM4->CNTR = 0x00; /*!< counter register */
TIM4->PSCR = 0x07; /*!< prescaler register */
TIM4->ARR = 249; /*!< auto-reload register */
//TIM4->EGR = 0x01; /*!< event generation register */
//enableInterrupts();
//TIM4->CR1 |= 0x01; // enable CEN
}
中断函数:
INTERRUPT_HANDLER(TIM4_UPD_OVF_IRQHandler, 23)
{
/* In order to detect unexpected events during development,
it is recommended to set a breakpoint on the following instruction.
*/
//TIM4_ClearITPendingBit(TIM4_IT_UPDATE);
TIM4->SR1 = 0xfe; //clear UIF flag
//SysTaskFlag |= 0x01;
Gpio_Reverse(GPIOB,0x10);
SysTask10msCnt++;
if(SysTask10msCnt >= SYSTASK_10MS_CNT)
{
SysTask10msCnt = 0;
SysTaskTicksFlag |= 0x01;
}
SysTask100msCnt++;
if(SysTask100msCnt >= SYSTASK_100MS_CNT)
{
SysTask100msCnt = 0;
SysTaskTicksFlag |= 0x02;
SysTask1sCnt++;
if(SysTask1sCnt >= SYSTASK_1S_CNT)
{
SysTask1sCnt = 0;
SysTaskTicksFlag |= 0x08;
SysTask5sCnt++;
if(SysTask5sCnt >= SYSTASK_5S_CNT)
{
SysTask5sCnt = 0;
SysTaskTicksFlag |= 0x10;
}
SysTask1minCnt++;
if(SysTask1minCnt >= SYSTASK_1MIN_CNT)
{
SysTask1minCnt = 0;
SysTaskTicksFlag |= 0x20;
}
}
}
SysTask500msCnt++;
if(SysTask500msCnt >= SYSTASK_500MS_CNT)
{
SysTask500msCnt = 0;
SysTaskTicksFlag |= 0x04;
}
}
主函数:
main()
{
SysClkInit();
Gpio_Init_Set();
TIM4_Init();
GPIOB->ODR = 0x00;
delayxus(100);
GPIOB->ODR |= 0x30;
enableInterrupts();
TIM4->CR1 |= 0x01;
while (1)
{
//delayxus(1000);
//GPIOB->ODR = 0x00;
//GPIO_TEST_Cnt++;
//if( GPIO_TEST_Cnt == 40000)
//{
GPIO_TEST_Cnt = 0;
// Gpio_Reverse(GPIOB,0x30);
//}
if((SysTaskTicksFlag & 0x08) == 0x08)
{
SysTaskTicksFlag &= 0xf7;
Gpio_Reverse(GPIOB,0x20);
}
}
}
求大神们指教。