我正在尝试使用8-1 multiplexer
mega16
尝试最大化输入引脚
所以我让我的程序扫描multiplexer
的所有地址并听一个interrupt
如果发生中断,程序检查此时发送的是哪个地址然后在LCD上打印一个字符串(它是由switch case管理)...
问题是 :: 当一个中断发生时,它进入交换机案例并执行它启动的那个案例
EX : 如果我按下第一个按钮(第一个地址),它将执行所有情况, 但是,如果我按下第二个,它将执行它'案件和第三个案件ans依此类推
int main(void)
{
//////////////////////
SETMUSK(MCUCR,ISC01);
/* When(ISC01 =1 and ISC00 =0 )The falling edge of INT0 generates an interrupt request. so we can use Internal PUll UP Resistance*/
CLEARMUSK(MCUCR,ISC00);
///////////////////////
GICR = 0x40;
CLEARMUSK(SFIOR,PUD); //Enabling Pull up resistor
DDRC = 0xFF;
LCD_Init();
DDRC = 0xFF;
DDRA = 0xFF;
DDRD = 0x00;
LCD_send_command(CLEAR_DISPLAY_AND_RAM);
LCD_display_string("Program Starting !!");
_delay_ms(250);
_delay_ms(250);
_delay_ms(250);
_delay_ms(250);
_delay_ms(250);
_delay_ms(250);
_delay_ms(250);
LCD_send_command(CLEAR_DISPLAY_AND_RAM);
sei(); // enabling global interrupt musk
while(1)
{
for (PORTA=0x00;PORTA <= 7;PORTA++) ;
//TODO:: Please write your application code
}
}
ISR(INT0_vect)/*sending the ISR address to the vector table using this statement here (INT0_vect)*/
{
switch (PINA)
{
case Addr0 :
{
LCD_send_command(CLEAR_DISPLAY_AND_RAM);
LCD_display_string("First");
_delay_ms(200);
LCD_send_command(CLEAR_DISPLAY_AND_RAM);
break;
}
case Addr1 :
{
LCD_send_command(CLEAR_DISPLAY_AND_RAM);
LCD_display_string("Second");
_delay_ms(200);
LCD_send_command(CLEAR_DISPLAY_AND_RAM);
break;
}
case Addr2 :
{
LCD_send_command(CLEAR_DISPLAY_AND_RAM);
LCD_display_string("Third");
_delay_ms(200);
LCD_send_command(CLEAR_DISPLAY_AND_RAM);
break;
}
case Addr3 :
{
LCD_send_command(CLEAR_DISPLAY_AND_RAM);
LCD_display_string("Fourth");
_delay_ms(250);
LCD_send_command(CLEAR_DISPLAY_AND_RAM);
break;
}
case Addr4 :
{
LCD_send_command(CLEAR_DISPLAY_AND_RAM);
LCD_display_string("FiFth");
_delay_ms(250);
LCD_send_command(CLEAR_DISPLAY_AND_RAM);
break;
}
case Addr5 :
{
LCD_send_command(CLEAR_DISPLAY_AND_RAM);
LCD_display_string("sixth");
_delay_ms(250);
LCD_send_command(CLEAR_DISPLAY_AND_RAM);
break;
}
case Addr6 :
{
LCD_send_command(CLEAR_DISPLAY_AND_RAM);
LCD_display_string("seventh");
_delay_ms(250);
LCD_send_command(CLEAR_DISPLAY_AND_RAM);
break;
}
case Addr7 :
{
LCD_send_command(CLEAR_DISPLAY_AND_RAM);
LCD_display_string("eights");
_delay_ms(250);
LCD_send_command(CLEAR_DISPLAY_AND_RAM);
break;
}
//default:
//break;
}
}
MUX.h
{
#define Addr0 0x00 //00000000
#define Addr1 0x01 //00000001
#define Addr2 0x02 //00000010
#define Addr3 0x03 //00000011
#define Addr4 0x04 //00000100
#define Addr5 0x05 //00000101
#define Addr6 0x06 //00000110
#define Addr7 0x07 //00000111
}