the while() is just a debounce
its not going to debounce much
.. set the interrupt to trigger on rising edge (button release) in the start of the interrupt routine disable interrup, and before you leave enable it again .. duration of the interrupt routine will do the "debouncing"
even that is not needed as you clear IFS0bits.INT0IF at the end of the routine .. so any "bounces" will not trigger the interrupt again until it ends...
the wile() will just pick up the "first bounce" ...
when you are not doing this in interrupt then some delay is needed in order for software debounce to work properly
Code:
while(!pressed);
delay(1ms); //wait a bit for input to stabilize
while(pressed);
as for example this do not work:
Code:
count = 0;
while(1){
while(!pressed1);
while(pressed1);
++count;
if (pressed2) break;
}
printf("%i", count);
you'd expect this to count how many times "pressed1" button was pressed from start until you press "pressed2" ... what happens is that for each time you press "pressed1" button the count will increment between 1 and 30 times because of the "contact bounce"...
in order to make it work properly - add a small delay between press and release check
Code:
...
while(!pressed);
delay(1ms);
while(pressed);
...
hope that helps, the hw debounce is easy so I prefer it .. but .. you can do this way too ... but no need to do it in interrupt as interrupt itself is debouncing it...