ATmega16做的流水灯为什么显示不正常?
#include <mega16.h>
#include <stdlib.h>
#include <delay.h>
#define uchar unsigned char
#define uint unsigned int
#define BIT(x) (1<<(x))
#define dlyTime 500
uchar i;
uchar light;
uchar keyFlag=0;
uchar light;
uchar key_press(){
uchar j;
j=PIND;
j=j&0x0C;
if(j==0x0C){
return 0;
}
else{
return 1;
}
}
interrupt [2] void int0(){
delay_ms(10);
if(key_press()){
keyFlag=1;
i=0;
light=0;
PORTA=0xFF;
delay_ms(dlyTime);
while(key_press());
}
}
interrupt [3] void int1(){
delay_ms(10);
if(key_press()){
keyFlag=2;
i=0;
light=0;
PORTA=0xFF;
delay_ms(dlyTime);
while(key_press());
}
}
void port_init(void){
DDRA|=0xFF;
PORTA|=0xFF;
DDRD&=~BIT(2);
DDRD&=~BIT(3);
PORTD|=BIT(2);
PORTD|=BIT(3);
}
void main(void){
i=0;
light=0x00;
port_init();
MCUCR|=0x0A;
GICR|=BIT(7);
GICR|=BIT(6);
GICR&=~BIT(5);
GIFR|=BIT(7);
GIFR|=BIT(6);
#asm("sei");
while(1){
if(i==8){
i=0;
light=0;
PORTA=0xFF;
delay_ms(dlyTime);
}
if(keyFlag == 1) light = light | (0x80 >> i);
if(keyFlag == 2) light = light | (0x01 << i);
PORTA = ~(light);
delay_ms(dlyTime);
i++;
};
}