AVR Int0中斷的c語言編程
#define uchar unsigned char
#define uint unsigned int
uchar Table[10]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
uchar Da
uchar Da
void DelayMs(uint i) //0.25ms
{uchar j;
for(;i!=0;i--)
{for(j=250;j!=0;j--) {;}}
}
void Display(uchar *p) //間隔5ms顯示
{uchar i,sel=0x01;
for(i=0;i<4;i++)
{PORTA=sel;
PORTC=0xff-Table[p[i]];
DelayMs(20);
sel=sel<<1;
}
}
void main(void)
{uint i;
DDRA=0xff; //設(shè)置A口為不帶上拉輸入;
PORTA=0xff;
DDRC=0xff; //設(shè)置C口為推挽1輸出;
PORTC=0xff;
DDRD=0xff; //設(shè)置D口為上拉輸入
PORTD=0xff;
PORTA=0xff;
PORTC=0x00;
DelayMs(10000);
MCUCR=0x00;//下降沿
GIMSK=0x40;//int0
GIFR=0xff;
SREG=SREG|0x80;
while(1){Display(Da
/*{if((GIFR&0x40)==0x40) {GIFR=0xff;Display(Da
else
}*/
}
#pragma interrupt_handler int0:2
void int0(void)
{Display(Da
評論