/* Global values */
u32 Switch1Stable = 0;
u32 Switch2Stable = 0;
/* Function to check for the switch stability*/
/* Switch1 & Switch2 values passed to this function as per switch status */
1---->depressed
0----->released
/* This function is called for every 1 ms */
static void voSwitchStability(bool Switch1, bool Switch2)
{
static u32 Switch1TimeStamp;
static u32 Switch2TimeStamp;
u32 Switch1Time = 1000;
u32 Switch2Time = 1000;
if(Switch1^Switch1Stable) /* if both are 0 or 1 no need to perform logic */
{
/* if switch 1 is pressed */
if(1 == Switch1)
{
if(( Switch1TimeStamp) >= Switch1Time)
{
/* switch1 is stable */
Switch1Stable = 1;
}
else if((Switch1TimeStamp) < Switch1Time)
{
/* Increment the switch1 time stamp */
Switch1TimeStamp++;
}
else
{
/* No Action */
}
}
else
{
/* Switch 1 reset */
Switch1Stable = 0;
}
}
else
{
/* reset time stamp */
Switch1TimeStamp = 0;
}
if(Switch2^Switch2Stable) /* if both are 0 or 1 no need to perform logic */
{
/* if switch 2 is pressed */
if(1 == Switch2)
{
if((Switch2TimeStamp) >= Switch2Time)
{
/* switch2 is stable */
Switch2Stable = 1;
}
else if((Switch2TimeStamp) < Switch2Time)
{
/* Increment switch2 time stamp*/
Switch2TimeStamp++;
}
else
{
/* No Action */
}
}
else
{ /* switch2 is released */
Switch2Stable = 0;
}
}
else
{
/* reset time stamp*/
Switch2TimeStamp = 0;
}
}