打印

请教 无法进入中断 查了几个小时 认为问题点都改过来了

[复制链接]
1473|3
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
57tm|  楼主 | 2012-5-8 16:01 | 只看该作者 |只看大图 回帖奖励 |倒序浏览 |阅读模式
本帖最后由 57tm 于 2012-5-8 16:19 编辑

TIMR8  的中断

也查了一下以前的资料,情况是

1.timr81_int.asm 中添加了 ljmp _Timer8_1_ISR_C
仍然不行




源代码如下

#pragma interrupt_handler Timer8_1_ISR_C
void Timer8_1_ISR_C(void)
{
    static BYTE ucCnt = 0;
    ucCnt++;
    if(ucCnt == 100){
           ucCnt = 0;
            PRT1DR ^=  BIT_MASK6;

    }
//return;
}

void main(void)
{

  M8C_EnableGInt ; // Uncomment this line to enable Global Interrupts
  Timer8_1_WritePeriod(10);//vc3 = vc1/16/5/100    T unit = 1ms   
  Timer8_WriteCompareValue(0x00);
  Timer8_1_EnableInt();
  Timer8_1_Start();
  
// Insert your main routine code here.
while(1){
   
}
模块配置如下:

TIMR8配置.JPG (22.98 KB )

TIMR8配置.JPG
沙发
57tm|  楼主 | 2012-5-8 16:09 | 只看该作者
本帖最后由 57tm 于 2012-5-8 16:12 编辑

_Timer8_1_ISR:

   ;@PSoC_UserCode_BODY@ (Do not change this line.)
   ;---------------------------------------------------
   ; Insert your custom assembly code below this banner
   ;---------------------------------------------------
   ;   NOTE: interrupt service routines must preserve
   ;   the values of the A and X CPU registers.
   
   ;---------------------------------------------------
   ; Insert your custom assembly code above this banner
   ;---------------------------------------------------
   ljmp _Timer8_1_ISR_C
   //_Timer8_1_ISR_C
   ;---------------------------------------------------
   ; Insert a lcall to a C function below this banner
   ; and un-comment the lines between these banners
   ;---------------------------------------------------
   
   pRESERVE_CPU_CONTEXT
   ;lcall _My_C_Function
   ;RESTORE_CPU_CONTEXT
   
   ;---------------------------------------------------
   ; Insert a lcall to a C function above this banner
   ; and un-comment the lines between these banners
   ;---------------------------------------------------
   ;@PSoC_UserCode_END@ (Do not change this line.)

   reti

使用特权

评论回复
板凳
PSoC小子| | 2012-5-8 17:24 | 只看该作者
static BYTE ucCnt = 0; 这一句应该定义成全局变量。 你这里每次进入中断时都对 ucCnt 重新定义并赋值 0, 这样 ucCnt 只能在 0 和 1 之间变化,不会到达 100.

改成这样试一下:
#include <m8c.h>        // part specific constants and macros
#include "PSoCAPI.h"    // PSoC API definitions for all User Modules

static BYTE ucCnt;

#pragma interrupt_handler Timer8_1_ISR_C
void Timer8_1_ISR_C(void)
{
        ucCnt++;
    if(ucCnt == 100)
        {
        ucCnt = 0;
        PRT1DR ^= 0x40;
    }
}

void main(void)
{

        M8C_EnableGInt ; // Uncomment this line to enable Global Interrupts
        Timer8_1_WritePeriod(10);//vc3 = vc1/16/5/100    T unit = 1ms   
        Timer8_1_WriteCompareValue(0x00);
        Timer8_1_EnableInt();
        Timer8_1_Start();
       
        while(1)
        {
                ;
        }
   
}

使用特权

评论回复
地板
57tm|  楼主 | 2012-5-9 09:10 | 只看该作者
问题找到 是Timer8_1_WritePeriod(10);下面那条语句写成了Timer8_1_WritePeriod(0);
另外模块中断类型要选对  T Count 溢出类型

另:static 变量的作用就是函数内局部变量保存

还是谢谢楼上耐心读了代码

使用特权

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

本版积分规则

30

主题

79

帖子

2

粉丝