CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

push button

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
IceMetal



Joined: 20 Nov 2008
Posts: 79
Location: white Plains, NY

View user's profile Send private message Yahoo Messenger

push button
PostPosted: Sat Jan 17, 2009 4:14 am     Reply with quote

I created this simple program for a push button switch, when I press the button the led should stay on, and when I press again the led should go off, the problem is that I have to press the button a few times for the led to go off and pressed a few times for the led to go on,but it works great when I send the 0 and 1 command, whats wrong with my code?? Crying or Very sad

Code:
#include <16F887.h>             // header file for the PIC16F887                           
                               
#FUSES NOWDT               
#FUSES NOMCLR
#FUSES NOCPD
#FUSES NOBROWNOUT            
#FUSES XT 

#use delay(clock=4000000)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8)
/////////////////////////////////////////////////////////////////////////////////

ledon(){
while(1){
  output_low(PIN_b1);
if (kbhit() && getc()=='0')
break;
if(!Input(PIN_B0))
break;
}
}


Void Main()
{
While(1)
  {
   if (kbhit() && getc()=='1')ledon(); 
  if(!Input(PIN_B0))ledon();
else output_high(PIN_b1);    //led off
  }
}


Thank you.
drh



Joined: 12 Jul 2004
Posts: 192
Location: Hemet, California USA

View user's profile Send private message

PostPosted: Sat Jan 17, 2009 8:51 am     Reply with quote

Have a look at this:
http://www.ganssle.com/debouncing.pdf
_________________
David
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sat Jan 17, 2009 1:19 pm     Reply with quote

Your code polls Pin B0 which I assume has a push-button switch on it
But you also are reading a character from the UART, which comes in
from a terminal program when you press a key on your PC's keyboard.

Is it your intention to use these two methods of getting input ?
The push-button on Pin B0 has nothing to do with the UART functions.
IceMetal



Joined: 20 Nov 2008
Posts: 79
Location: white Plains, NY

View user's profile Send private message Yahoo Messenger

PostPosted: Sat Jan 17, 2009 11:23 pm     Reply with quote

PCM programmer wrote:
Your code polls Pin B0 which I assume has a push-button switch on it
But you also are reading a character from the UART, which comes in
from a terminal program when you press a key on your PC's keyboard.

Is it your intention to use these two methods of getting input ?
The push-button on Pin B0 has nothing to do with the UART functions.


yes I'm trying to do it both ways, one with the UART and one with the push button on pin B0, but so far the UART works, and the push button only sometimes
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sat Jan 17, 2009 11:54 pm     Reply with quote

See the link labeled "simple" in this thread on debouncing.
http://www.ccsinfo.com/forum/viewtopic.php?t=36222
IceMetal



Joined: 20 Nov 2008
Posts: 79
Location: white Plains, NY

View user's profile Send private message Yahoo Messenger

PostPosted: Sun Jan 18, 2009 4:50 am     Reply with quote

PCM programmer wrote:
See the link labeled "simple" in this thread on debouncing.
http://www.ccsinfo.com/forum/viewtopic.php?t=36222


thank you PCM programmer that really helped me Smile
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group