標(biāo)題:
求助:ATMEG128外部中斷程序進(jìn)不了中斷
[打印本頁(yè)]
作者:
明月輕風(fēng)
時(shí)間:
2013-10-27 19:33
標(biāo)題:
求助:ATMEG128外部中斷程序進(jìn)不了中斷
#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)不了中斷呢:謝謝
作者:
丿Damon丨
時(shí)間:
2014-9-12 22:50
我也是
作者:
mqwu
時(shí)間:
2014-9-16 09:27
下面是我今天早上寫(xiě)的外部中斷, 已經(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);
}
作者:
mqwu
時(shí)間:
2014-9-16 09:29
更改code 如下
作者:
mqwu
時(shí)間:
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)
{
;
}
}
歡迎光臨 (http://www.torrancerestoration.com/bbs/)
Powered by Discuz! X3.1