silveroblado WROTE:SW1=RBO
LED1=RB6
unsigned int count;
Void main(void)
{
while(1)
{
If(SW1==0)
{
count++;
while(count<20)
{
LED1=1;
delay(4000);
LED1=0;
}
}
}
}
from the code your shared and explanation, the code is working as it should. Though I din go through the code in details, but looking at the logic, it works as what you get

OK, in your while(1) loop, you check SW1 press using if, that is nothing wrong. Now if SW1 is press, count is increase by 1. Assume this is 1st press, count become 1 and program will proceed to go to another while loop to check count value. If count value is less than 20, it will enter the while loop. As this is 1st press, count is 1, it is true and program enter while loop. That is major mistake here. Since this is while loop, it will loop until the (count < 20 ) become false. So my question is, while count increase and become more than 20?
OK, now go to the LED blinking part. As you might have agreed, the while loop of count < 20 will keep loop so the LED will on and delay for sometime and off, since it is capture by while loop, LED will on again and delay for sometime and off, this will repeat again and again, until you reset. Since On time is extremely longer than off time, you will only see the LED as on.
There is nothing wrong with the board from what I see, the PIC do what it is being programmed to do
