如题: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);
}
}
}
求大神们指教。
此帖出自
小平头技术问答
struct interrupt_vector const _vectab[] = {
{0x82, (interrupt_handler_t)_stext}, /* reset */
{0x82, NonHandledInterrupt}, /* trap */
{0x82, NonHandledInterrupt}, /* irq0 */
{0x82, NonHandledInterrupt}, /* irq1 */
{0x82, NonHandledInterrupt}, /* irq2 */
{0x82, NonHandledInterrupt}, /* irq3 */
{0x82, NonHandledInterrupt}, /* irq4 */
{0x82, NonHandledInterrupt}, /* irq5 */
{0x82, NonHandledInterrupt}, /* irq6 */
{0x82, NonHandledInterrupt}, /* irq7 */
{0x82, NonHandledInterrupt}, /* irq8 */
{0x82, NonHandledInterrupt}, /* irq9 */
{0x82, NonHandledInterrupt}, /* irq10 */
{0x82, NonHandledInterrupt}, /* irq11 */
{0x82, NonHandledInterrupt}, /* irq12 */
{0x82, NonHandledInterrupt}, /* irq13 */
{0x82, NonHandledInterrupt}, /* irq14 */
{0x82, NonHandledInterrupt}, /* irq15 */
{0x82, NonHandledInterrupt}, /* irq16 */
{0x82, NonHandledInterrupt}, /* irq17 */
{0x82, NonHandledInterrupt}, /* irq18 */
{0x82, NonHandledInterrupt}, /* irq19 */
{0x82, NonHandledInterrupt}, /* irq20 */
{0x82, NonHandledInterrupt}, /* irq21 */
{0x82, NonHandledInterrupt}, /* irq22 */
//{0x82, (interrupt_handler_t)TIM4_Overglag_Interrupt}, /* irq23 */
{0x82,TIM4_UPD_OVF_IRQHandler},
{0x82, NonHandledInterrupt}, /* irq24 */
{0x82, NonHandledInterrupt}, /* irq25 */
{0x82, NonHandledInterrupt}, /* irq26 */
{0x82, NonHandledInterrupt}, /* irq27 */
{0x82, NonHandledInterrupt}, /* irq28 */
{0x82, NonHandledInterrupt}, /* irq29 */
};
太大意啦,希望大家以此为戒。
一周热门 更多>