I want to know about considerations about switch bouncing & debouncing in writing programs while using a switch to turn on LED or Buzzer.
How should i take it into consideration when writing the program.
Please mail me some example code if possible.
Any reference books or websites useful in embedded C programming, mail to me.
In one project (only 2 keys) I used timer for debouncing: read key once every 50ms, if key was previously down (key=1), there must be at least two key reads with key up (key=0) to accept next key press (hope you understand... it is difficult to explain.)
We,human beings, can't press a button more than 10 times in second.So it's enough to scan for a key press for 100 msecs.For example:
Example: (toggling the LED)
Code:
#include <16F84A.h>
#fuses XT,NOWDT,NOPROTECT
#use delay(clock=4000000)
#define BUTTON PIN_B0
#define LED PIN_B3
void main()
{
output_low(LED);
delay_ms(100);
while(TRUE)
{
if(input(BUTTON)==0) // The time the button is pressed
{
output_toggle(LED);
delay_ms(20);
while(input(BUTTON)==0); // wait until the button is released.
}
}
}