i use 89s52 but the principle is same
maybe is not the best variant but work !
while(1)
{
Sw_State = Switch_Get_Input(10);
Display_Switch_Update(Sw_State);
}
.....................................
char Switch_Get_Input(const unsigned char debounce_period)
{
char Return_value = 0x00;
if(Switch_Pin_1 == 0)
{
delay_ms(debounce_period);
if(Switch_Pin_1 == 0)
{
while(Switch_Pin_1 == 0);
Return_value = 0x01;
}
}
if(Switch_Pin_2 == 0)
{
delay_ms(debounce_period);
if(Switch_Pin_2 == 0)
{
while(Switch_Pin_2 == 0);
Return_value = 0x02;
}
}
if(Switch_Pin_3 == 0)
{
delay_ms(debounce_period);
if(Switch_Pin_3 == 0)
{
while(Switch_Pin_3 == 0);
Return_value = 0x03;
}
}
if(Switch_Pin_4 == 0)
{
delay_ms(debounce_period);
if(Switch_Pin_4 == 0)
{
while(Switch_Pin_4 == 0);
Return_value = 0x04;
}
}
return Return_value;
}
---------------------------------------------------------------
void Display_Switch_Update(const char SWITCH_STATUS)
{
switch (SWITCH_STATUS){
case 0x01 :
Some command;
break;
case 0x02 :
Some command;
break;
case 0x03 :
Some command;
break;
case 0x04 :
Some command;
break;
default:
Some command;
break;
}
}
..::SyRaX:..