What's wrong with line 9. Where it should be ?The Line 9 shouldn't be there!!
What's wrong with line 9. Where it should be ?The Line 9 shouldn't be there!!
I tested modified function but it's not workedIf you set it like that the rest of your code may not happen Your setting a input to 0 there no need to You don't need that
#define PushButton_Pressed 0
#define PushButton_Not_Pressed 1
int check_PushButton(void)
{
static int PushButton_status;
if(PushButton == PushButton_Pressed) // check if Button is pressed
{
Debounce(10000); //Wait for bouncing period
if(PushButton == PushButton_Pressed) // check Push Button is pressed again
{
PushButton_status = PushButton_Pressed ;
}
}
return PushButton_status;
}
Thats way to long of a delay you have to wait 1 second for each press it should be less then 100 I'd start at 50Debounce(10000);
I checked my code with 100 times but its not working. What's wrong in post #23. I am getting confuse with only pushbutton function.Right!!!! Its a toggle..
if button is pressed and LED is on, turn LED off.
if button is pressed and LED is off, turn it on..
Burt!! 10,000 equates to 140mS which I thought was enough... If you use 50 it would read the switch 100's of times...
#include<reg51.h>
sbit PushButton = P0^0;
sbit LED = P2^0;
#define PushButton_Not_Pressed 1
#define PushButton_Pressed 0
#define LED_OFF 0
#define LED_ON 1
#define PushButton_Pressed 0
#define PushButton_Not_Pressed 1
//Function for debouncing time
void Debounce(unsigned int M_count)
{
int count;
for (count = 0; count < M_count; count++);
}
int check_PushButton(void)
{
static int PushButton_status;
if(PushButton == PushButton_Pressed) // check if Button is pressed
{
Debounce(100); //Wait for bouncing period
if(PushButton == PushButton_Pressed) // check Push Button is pressed again
{
PushButton_status = PushButton_Pressed ;
}
}
return PushButton_status;
}
//Program start from here
void main(void)
{
LED = 0; //configuring as output pin
PushButton = 1; //Configuring as input pin
while(1)
{
if( check_PushButton()) //Check the Push Button status
{
LED = LED_ON; //Led On
}
else
{
LED = LED_OFF; //Led off
}
}
}
I have checked again code with 10000 times but led goes ON foreverIf you have a 12Mhz crystal... Each clock will be 1uS.. It takes about 14 cycles to do a integer for loop in C!!
int check_PushButton(void)
{
static int PushButton_status;
if(PushButton == PushButton_Pressed) // check if Button is pressed
{
Debounce(10000); //Wait for bouncing period
if(PushButton == PushButton_Pressed) // check Push Button is pressed again
{
PushButton_status = PushButton_Pressed ;
}
}
return PushButton_status;
}
What is you crystal speed???I have checked again code with 10000 times but led goes ON forever
#include <reg52.h>
sbit PushButton = P0^0 ; //switch connected to P0.1
sbit LED = P2^0 ; //LED connected to p2.0
#define PushButton_Not_Pressed 0
#define PushButton_Pressed 1
#define LED_OFF 0
#define LED_ON 1
//Function for debouncing time
void Debounce(unsigned int M_count)
{
int count;
for (count = 0; count < M_count; count++);
}
//Function to check the status of Push button
int check_PushButton(void)
{
static int PushButton_status;
if(!PushButton == PushButton_Pressed && PushButton_status == PushButton_Not_Pressed ) // check if Button is pressed
{
Debounce(10000); //Wait for bouncing period
if(!PushButton == PushButton_Pressed ) // check Push Button is pressed again
{
PushButton_status = PushButton_Pressed ;
}
}
else if (!PushButton == PushButton_Pressed && PushButton_status == PushButton_Pressed )
{
Debounce(10000); //Wait for bouncing period
if(!PushButton == PushButton_Pressed ) // check Push Button is pressed again
{
PushButton_status = PushButton_Not_Pressed ;
}
}
return PushButton_status;
}
//Program start from here
void main(void)
{
LED = 0; //configuring as output pin
PushButton = 1; //Configuring as input pin
while(1)
{
if( check_PushButton()) //Check the Push Button status
{
LED = LED_ON; //Led On
}
else
{
LED = LED_OFF; //Led off
}
}
}
int SWsave;
SWsave = 1;
if (PushButton == 0 )
{
SWsave = 0;
Debounce(10000);
}
if (PushButton && SWsave == 0 )
{
LED =~ LED; //Led On
}