vead
Full Member level 5
Hello
I have read that whenever we write program for push button we need debounce period. But in this program LED toggle without debounce time
When should I use debounce time for the Push button
I have read that whenever we write program for push button we need debounce period. But in this program LED toggle without debounce time
Code:
#include <reg51.h>
sbit SW = P2^1; //Connect switch to P2.1
sbit LED = P1^7; //Connect LED to p1.7
void main (void) {
while(1)
{
while(SW==1); //switch is not pressed
LED = ~ LED; //Toggle LED Status
while(SW==0); //switch is not released
}
}
When should I use debounce time for the Push button
Code:
#include <reg51.h>
sbit SW = P2^1; //Connect switch to P2.1
sbit LED = P1^7; //Connect LED to p1.7
void Deboune(unsigned int x);
void main (void) {
while(1)
{
while(SW==1); //switch is not pressed
Deboune(30000);
LED = ~ LED; //Toggle LED Status
while(SW==0); //switch is not released
Deboune(30000);
}
}
void Deboune(unsigned int x)
{
unsigned int k ;
for ( k = 0; k < x; k++);
}