找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 3805|回复: 4
打印 上一主题 下一主题
收起左侧

求助:ATMEG128外部中断程序进不了中断

[复制链接]
跳转到指定楼层
楼主
ID:56375 发表于 2013-10-27 19:33 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
#include <iom128v.h>
#include <macros.h>
#progma interrupt_handler int2_interrupt:4
/******************************************************************************/
/*函数功能:外部中断初始化(按钮下降沿产生中断,中断源INT2)
/*输入参数:无
/*返回值: 无                         
/******************************************************************************/
void extinterrupt_init()
{
  DDRD&=~BIT(2);//PD2设为输入
  EICRA=0x65;//INT2 下降沿触发
  EIMSK=0X04;//INT2  外部中断使能
  SEI();
}

/******************************************************************************/
/*函数功能:外部中断源2产生下降沿触发中断,按钮按下动作
/*输入参数:
/*返回值: 无                         
/******************************************************************************/
void int2_interrupt()
{  
   
   PORTE&=~BIT(4);//点亮LED
}  
void main()
{
  
  CLI();
  DDRE|=BIT(4);
  PORTE|=BIT(4);//LED熄灭
  extinterrupt_init();
  while(1)
  {
    ;
  }

}


请问以上程序为什么在PD2由高电平到低电平时进不了中断呢:谢谢
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享淘帖 顶 踩
回复

使用道具 举报

沙发
ID:65146 发表于 2014-9-12 22:50 | 只看该作者
我也是
回复

使用道具 举报

板凳
ID:66032 发表于 2014-9-16 09:27 | 只看该作者
下面是我今天早上写的外部中断, 已经运行还可以
#include<iom128v.h>
#include<macros.h>
#define uchar           unsigned char
#define uint            unsigned int

#pragma interrupt_handler INT0_ISR:2 //ÏÂÃæμÄcodeò2¿éòÔ
//#pragma interrupt_handler  INT0_ISR:iv_INT0
#pragma interrupt_handler INT1_ISR:3  //ÏÂÃæμÄcodeò2¿éòÔ
//#pragma interrupt_handler  INT1_ISR:iv_INT1
uint count,num;
const uchar table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,
               0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71,0x40};
void delay(uint ms);
void port_Init(void);
void ExternalInterrupt_init(void);
void Numerical_display(uchar m, uchar n);

void main(void)
{   
     
    port_Init();
    ExternalInterrupt_init();
   
while(1)
   {
      
     Numerical_display(num/1000,0);   
     Numerical_display(num/100%10,1);
     Numerical_display(num/10%10,2);  
     Numerical_display(num%10,3);   
     Numerical_display(count/1000,4);
     Numerical_display(count/100%10,5);
     Numerical_display(count/10%10,6);   
     Numerical_display(count%10,7);             //μ÷óÃoˉêy£¬ÏÔê¾
   }

}

void INT0_ISR()       //ÖD¶Ï0·tÎñ3ìDò
   {
     count++;
     if(count==9999)
     count=0;
   }


void INT1_ISR()     //ÖD¶Ï1·tÎñ3ìDò
   {
     num++;
     if(num==9999)
     num=0;
  }

void delay(uint ms)
{
  uint i,j;
  for (i=0; i<ms; i++);
    for (j=0;j<1500;j++);

}

void port_Init(void)
{
    PORTA=0xFF;  //êy¾Y¿úÎaêä3ö
    DDRA=0xFF;

    PORTD=0xFF;  //Pull up;
    DDRD|=0xF0;   //set the PORT as input

}
void ExternalInterrupt_init(void)
{
  EICRA=0x0a; //falling edge trigger
// EICRA=0x0f; //rising edge trigger
  EIMSK|=0x03;  //Enable INT0 and INT1
  MCUCSR=0x00;  //¿ØÖÆoí×′쬼Ä′æÆ÷3õê¼»ˉ
  EIFR|=0x03;
  SREG|=BIT(7);

}
void Numerical_display(uchar m, uchar n)
{
      PORTD|=BIT(4);
      PORTA=table[m];
      PORTD&=~BIT(4);
      
      PORTA=0xff;
      PORTA&=~BIT(n);
      PORTD|=BIT(5);
      PORTD&=~BIT(5);
      delay(2);

}

   
回复

使用道具 举报

地板
ID:66032 发表于 2014-9-16 09:29 | 只看该作者
更改code 如下
回复

使用道具 举报

5#
ID:66032 发表于 2014-9-16 09:44 | 只看该作者
#include <iom128v.h>
#include <macros.h>
#progma interrupt_handler int2_interrupt:4
/******************************************************************************/
/*函数功能:外部中断初始化(按钮下降沿产生中断,中断源INT2)
/*输入参数:无
/*返回值: 无                        
/******************************************************************************/
void extinterrupt_init()
{
  DDRD&=~BIT(2);//PD2设为输入
  PORTD|=BIT(2); pull up;
  EICRA=0x02;//INT2 下降沿触发
  EIMSK=0X04;//INT2  外部中断使能
  SEI();
}

/******************************************************************************/
/*函数功能:外部中断源2产生下降沿触发中断,按钮按下动作
/*输入参数:
/*返回值: 无                        
/******************************************************************************/
void int2_interrupt()
{  
   
   PORTE&=~BIT(4);//点亮LED
   PORTE^=BIT(4);// use the toggle mode, you will see the change everytime
}  
void main()
{
  
  CLI();
  DDRE|=BIT(4);
  PORTE|=BIT(4);//LED熄灭
  extinterrupt_init();
  while(1)
  {
    ;
  }

}
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表