I am running the below-given program but the problem is that for loop runs only once and turns on the LED and then Turns OFF. It should run for 5 times. Below is the code:
void led(void)
{
RB0=~RB0;
__delay_ms(delay);
RB0=~RB0;
}
void main(void)
{
ANSEL = 0; //Disable Analog PORTA
TRISA0 = 1; //Make RA0 as Input
TRISB = 0x00;
PORTA = 0;
PORTB = 0x01;
// RB0=0;
while(1)
{
//Switch Pressed
if(swch==0) //Check for Switch Pressed
{
__delay_ms(delay_debounce); //Switch Debounce Delay
if(swch==0) //Check again Switch Pressed
{
//Blink LED at PORT RB0
for (int i = 0; i < 2; i++)
{
led();
}
}
}
else if(swch==1)
{
//Do Nothing
}
}
return;
}