标题:
求助:ATMEG128外部中断程序进不了中断
[打印本页]
作者:
明月轻风
时间:
2013-10-27 19:33
标题:
求助:ATMEG128外部中断程序进不了中断
#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由高电平到低电平时进不了中断呢:谢谢
作者:
丿Damon丨
时间:
2014-9-12 22:50
我也是
作者:
mqwu
时间:
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);
}
作者:
mqwu
时间:
2014-9-16 09:29
更改code 如下
作者:
mqwu
时间:
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)
{
;
}
}
欢迎光临 (http://www.51hei.com/bbs/)
Powered by Discuz! X3.1