打印
[STM8]

求大神帮忙啊,总进异常中断,为什么啊?

[复制链接]
1011|3
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
xingshaobang|  楼主 | 2014-4-7 14:50 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
TI, TE, ST, IO, se
本帖最后由 xingshaobang 于 2014-4-8 15:28 编辑

我用ST的例子建立一个工程,怎么就总是进异常中断呢?大神帮忙啊

主函数文件:
/* MAIN.C file
*
* Copyright (c) 2002-2005 STMicroelectronics
*/
#include "stm8s.h"
/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
#define TIM4_PERIOD       124
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
__IO uint32_t TimingDelay = 0;

void Delay(__IO uint32_t nTime);
void TimingDelay_Decrement(void);
static void CLK_Config(void);
static void TIM4_Config(void);

main()
{
          /* Clock configuration -----------------------------------------*/
  CLK_Config();  
  /* TIM4 configuration -----------------------------------------*/
  TIM4_Config();   

        while (1)
                {Delay(100);};
}
static void CLK_Config(void)
{
    /* Initialization of the clock */
    /* Clock divider to HSI/1 */
    CLK_HSIPrescalerConfig(CLK_PRESCALER_HSIDIV1);
}

static void TIM4_Config(void)
{
  /* TIM4 configuration:
   - TIM4CLK is set to 16 MHz, the TIM4 Prescaler is equal to 128 so the TIM1 counter
   clock used is 16 MHz / 128 = 125 000 Hz
  - With 125 000 Hz we can generate time base:
      max time base is 2.048 ms if TIM4_PERIOD = 255 --> (255 + 1) / 125000 = 2.048 ms
      min time base is 0.016 ms if TIM4_PERIOD = 1   --> (  1 + 1) / 125000 = 0.016 ms
  - In this example we need to generate a time base equal to 1 ms
   so TIM4_PERIOD = (0.001 * 125000 - 1) = 124 */

  /* Time base configuration */
  TIM4_TimeBaseInit(TIM4_PRESCALER_128, TIM4_PERIOD);
  /* Clear TIM4 update flag */
  TIM4_ClearFlag(TIM4_FLAG_UPDATE);
  /* Enable update interrupt */
  TIM4_ITConfig(TIM4_IT_UPDATE, ENABLE);

  /* enable interrupts */
  enableInterrupts();

  /* Enable TIM4 */
  TIM4_Cmd(ENABLE);
}


void TimingDelay_Decrement(void)
{
  if (TimingDelay != 0x00)
  {
    TimingDelay--;
  }
}



void Delay(__IO uint32_t nTime)
{
  TimingDelay = nTime;

  while (TimingDelay != 0);
}


总是跳到下面这个函数,为什么呢?

@far @interrupt void NonHandledInterrupt (void)
{
        /* in order to detect unexpected events during development,
           it is recommended to set a breakpoint on the following instruction
        */
        return;
}

补充,stm8s_it.c中与TIM4中断有关部分
#ifdef STM8S903/**
  * @brief  Timer6 Update/Overflow/Trigger Interrupt routine
  * @param  None
  * @retval None
  */
INTERRUPT_HANDLER(TIM6_UPD_OVF_TRG_IRQHandler, 23)
{
  /* In order to detect unexpected events during development,
     it is recommended to set a breakpoint on the following instruction.
  */
}
#else /*STM8S208, STM8S207, STM8S105 or STM8S103 or STM8AF62Ax or STM8AF52Ax or STM8AF626x */
/**
  * @brief  Timer4 Update/Overflow Interrupt routine
  * @param  None
  * @retval None
  */
INTERRUPT_HANDLER(TIM4_UPD_OVF_IRQHandler, 23)
{
   TimingDelay_Decrement();
  /* Cleat Interrupt Pending bit */
  TIM4_ClearITPendingBit(TIM4_IT_UPDATE);

}
#endif /*STM8S903*/










  

TCS.rar

265.67 KB

沙发
朝阳之光| | 2014-4-7 17:17 | 只看该作者
直接把代码贴过来,没人会下载你的代码看的

使用特权

评论回复
板凳
一清如水| | 2014-4-7 17:35 | 只看该作者
打包的NB大神,帮顶

使用特权

评论回复
地板
xingshaobang|  楼主 | 2014-4-8 15:23 | 只看该作者
朝阳之光 发表于 2014-4-7 17:17
直接把代码贴过来,没人会下载你的代码看的

谢谢提醒,不怎么泡坛子,不懂规矩,不好意思

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

2

主题

9

帖子

0

粉丝