View previous topic :: View next topic |
Author |
Message |
IceMetal
Joined: 20 Nov 2008 Posts: 79 Location: white Plains, NY
|
push button |
Posted: Sat Jan 17, 2009 4:14 am |
|
|
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??
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
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sat Jan 17, 2009 1:19 pm |
|
|
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
|
|
Posted: Sat Jan 17, 2009 11:23 pm |
|
|
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
|
|
|
IceMetal
Joined: 20 Nov 2008 Posts: 79 Location: white Plains, NY
|
|
Posted: Sun Jan 18, 2009 4:50 am |
|
|
thank you PCM programmer that really helped me |
|
|
|