找回密碼
 立即注冊(cè)

QQ登錄

只需一步,快速開(kāi)始

搜索
查看: 4439|回復(fù): 4
打印 上一主題 下一主題
收起左側(cè)

求助:ATMEG128外部中斷程序進(jìn)不了中斷

[復(fù)制鏈接]
跳轉(zhuǎn)到指定樓層
樓主
ID:56375 發(fā)表于 2013-10-27 19:33 | 只看該作者 回帖獎(jiǎng)勵(lì) |倒序?yàn)g覽 |閱讀模式
#include <iom128v.h>
#include <macros.h>
#progma interrupt_handler int2_interrupt:4
/******************************************************************************/
/*函數(shù)功能:外部中斷初始化(按鈕下降沿產(chǎn)生中斷,中斷源INT2)
/*輸入?yún)?shù):無(wú)
/*返回值: 無(wú)                         
/******************************************************************************/
void extinterrupt_init()
{
  DDRD&=~BIT(2);//PD2設(shè)為輸入
  EICRA=0x65;//INT2 下降沿觸發(fā)
  EIMSK=0X04;//INT2  外部中斷使能
  SEI();
}

/******************************************************************************/
/*函數(shù)功能:外部中斷源2產(chǎn)生下降沿觸發(fā)中斷,按鈕按下動(dòng)作
/*輸入?yún)?shù):
/*返回值: 無(wú)                         
/******************************************************************************/
void int2_interrupt()
{  
   
   PORTE&=~BIT(4);//點(diǎn)亮LED
}  
void main()
{
  
  CLI();
  DDRE|=BIT(4);
  PORTE|=BIT(4);//LED熄滅
  extinterrupt_init();
  while(1)
  {
    ;
  }

}


請(qǐng)問(wèn)以上程序?yàn)槭裁丛赑D2由高電平到低電平時(shí)進(jìn)不了中斷呢:謝謝
分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏 分享淘帖 頂 踩
回復(fù)

使用道具 舉報(bào)

沙發(fā)
ID:65146 發(fā)表于 2014-9-12 22:50 | 只看該作者
我也是
回復(fù)

使用道具 舉報(bào)

板凳
ID:66032 發(fā)表于 2014-9-16 09:27 | 只看該作者
下面是我今天早上寫的外部中斷, 已經(jīng)運(yùn)行還可以
#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);

}

   
回復(fù)

使用道具 舉報(bào)

地板
ID:66032 發(fā)表于 2014-9-16 09:29 | 只看該作者
更改code 如下
回復(fù)

使用道具 舉報(bào)

5#
ID:66032 發(fā)表于 2014-9-16 09:44 | 只看該作者
#include <iom128v.h>
#include <macros.h>
#progma interrupt_handler int2_interrupt:4
/******************************************************************************/
/*函數(shù)功能:外部中斷初始化(按鈕下降沿產(chǎn)生中斷,中斷源INT2)
/*輸入?yún)?shù):無(wú)
/*返回值: 無(wú)                        
/******************************************************************************/
void extinterrupt_init()
{
  DDRD&=~BIT(2);//PD2設(shè)為輸入
  PORTD|=BIT(2); pull up;
  EICRA=0x02;//INT2 下降沿觸發(fā)
  EIMSK=0X04;//INT2  外部中斷使能
  SEI();
}

/******************************************************************************/
/*函數(shù)功能:外部中斷源2產(chǎn)生下降沿觸發(fā)中斷,按鈕按下動(dòng)作
/*輸入?yún)?shù):
/*返回值: 無(wú)                        
/******************************************************************************/
void int2_interrupt()
{  
   
   PORTE&=~BIT(4);//點(diǎn)亮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)
  {
    ;
  }

}
回復(fù)

使用道具 舉報(bào)

本版積分規(guī)則

手機(jī)版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術(shù)交流QQ群281945664

Powered by 單片機(jī)教程網(wǎng)

快速回復(fù) 返回頂部 返回列表