以下是俺无聊时,编的一个外部中断程序,但是无论怎么改变中断口,程序都只能跑向外部中断0,这是为什么呀,请大家检查一下。
#include<avr/io.h>
#include<avr/interrupt.h>
#include<avr/eeprom.h>
/*宏定义PORTB口前三个脚的状态*/
#define red_on PORTB&(1>>0)
#define red_off PORTB|1
#define green_on PORTB&(~(1<<1))
#define green_off PORTB|(1<<1)
#define yellow_on PORTB&(~(1<<2))
#define yellow_off PORTB|(1<<2)
void data_initialize(void)/* 端口初始化 */
{DDRD=0x00;/* D口为输入口*/
DDRB=0xff;/* f口为输出口*/
PORTB=0x00;
PORTD=0xfb;
}
SIGNAL(SIG_INTERRUPT0)/*外部中断0,触发外部中断1*/
{
PORTB=yellow_off;
PORTB=green_off;
PORTB=red_on;
eeprom_busy_wait();
PORTD=eeprom_read_byte((void*)0xf1);
}
SIGNAL(SIG_INTERRUPT1)/*外部中断1,触发外部中断2*/
{
PORTB=red_off;
PORTB=green_off;
PORTB=yellow_on;
PORTD=eeprom_read_byte((void*)0xf2);
}
SIGNAL(SIG_INTERRUPT2)/*外部中断2,触发外部中断3*/
{
PORTB=red_off;
PORTB=red_off;
PORTB=green_on;
PORTD=eeprom_read_byte((void*)0xf3);
}
SIGNAL(SIG_INTERRUPT3)/*外部中断4,触发外部中断1*/
{
PORTB=red_off;
PORTB=red_off;
PORTB=green_off;
PORTD=eeprom_read_byte((void*)0xf4);
}
void int_initialize(void)/*外部中断参数设置,低电平触发中断,0-3中断使能*/
{
EICRA=0x00;
EIMSK|=0x0f;
sei();
}
int main(void)
{
eeprom_busy_wait();
eeprom_write_byte((void *)0xf1,0xfd);
eeprom_busy_wait();
eeprom_busy_wait();
eeprom_write_byte((void *)0xf2,0xfb);
eeprom_busy_wait();
eeprom_busy_wait();
eeprom_write_byte((void *)0xf3,0xf7);
eeprom_busy_wait();
eeprom_busy_wait();
eeprom_write_byte((void *)0xf4,0xfe);
/*-----------------------------------触发状态写入EEPROM*/
data_initialize();/*端口初始化参数*/
int_initialize();/*中断初始化端口*/
}
} |