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 support@ccsinfo.com

Pushbutton problems

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



Joined: 18 Dec 2007
Posts: 18

View user's profile Send private message

Pushbutton problems
PostPosted: Tue Dec 18, 2007 3:56 am     Reply with quote

Hi there,

i am wanting to perfrom rs232 comms with quite a few PICs. First of all since i am new to CCS i am constructing basic programs to help me get familiar with the syntax etc. My first program to blink an LED was no problem but now i want to use a pushbutton to turn on (when held) an LED on a 12F675. I have tried almost everything but still no luck the code i am using is:

#include <12F675.h>
#device ADC=10
#fuses INTRC_IO,NOWDT,NOPUT,NOPROTECT,NOCPD,NOMCLR
#use delay(clock=4000000)
#define GP0 PIN_A0
#define GP1 PIN_A1
#define GP2 PIN_A2
#define GP3 PIN_A3
#define GP4 PIN_A4
#define GP5 PIN_A5

void main()
{
while(1)
{
if ( input(GP1) )
output_high(GP2);

else
output_low(GP2);
}
}

i have tried variations to include if ( (input(PIN_A1) )==1) ans so on but all that happens is the LED remains on regardless of the state of the pushbutton.

Have i missed something?
Ttelmah
Guest







PostPosted: Tue Dec 18, 2007 4:25 am     Reply with quote

How is the 'pushbutton' connected?. To detect a switch, you normally need it to connect the button to 0v (say), and have a _pull up resistor_, so that the pin goes high when it is not pressed, and low when it is pressed. A button on it's own (without a resistor), can't (easily...) be detected. The PIC itself, has the ability to turn on internal 'resistors' for this type of operation. Unless there is something like this, to change the state of the pin, when the button is not pressed, the input, will pretty much stay at the state it was, when the button was pressed, and nothing will happen...
Look at the 'port_a_pullups' command, and wire your switch to 0v, then see what happens.

Best Wishes
apl01



Joined: 18 Dec 2007
Posts: 18

View user's profile Send private message

PostPosted: Tue Dec 18, 2007 4:32 am     Reply with quote

Yes you are right, silly me. Thanks for your help.
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