ATmega8 无法进入外中断,程序如下,目的是发生一次外中断累加一次data_1,并通过串口送到PC,上电后串口调试助手只能收到一次01,如果能进入中断应该能收到04啊,求教。多谢
#include <avr/io.h>
/***********************************宏定义**********************************/
#define fosc 11059200 //晶振8MHZ
#define baud 9600 //波特率
unsigned char data_1;//每触发一次中断,该值加1
unsigned char flag;//发生int0中断后,该值置0xFF
void uart0_init(void)
{
UCSRB = 0x00;
UCSRA = 0x00;
UCSRC =(1<<UCSZ1)|(1<<UCSZ0);
UBRRL=(fosc/16/(baud+1))%256;
UBRRH=(fosc/16/(baud+1))/256;
UCSRB =(1<<RXEN)|(1<<TXEN);
}
void int0_init(void)
{
MCUCR=(1<<ISC01);//INT0下降沿触发中断
GICR=(1<<INT0);//enable INT0
}
SIGNAL(SIG_INTERRUPT0)
{
cli();
flag=0xff;
putchar0(4);
sei();
}
void putchar0(unsigned char c)
{
while (!(UCSRA&(1<<UDRE)));
UDR=c;
}
int main(void)
{
uart0_init();
int0_init();
putchar0(1);
sei();
while(flag==0xff)
{
cli();
flag=0;
if(data_1<=255)
{
putchar0(data_1);
putchar0(2);
}
else
{
data_1=0;
putchar0(3);
}
sei();
}
} |