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

input and output on the same pic pin ?

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



Joined: 19 Jul 2007
Posts: 9

View user's profile Send private message

input and output on the same pic pin ?
PostPosted: Mon Jul 23, 2007 6:52 pm     Reply with quote

now i face a problem,
i no have any extra pin, so i need to drive a 7 segment led(commom anod) and at the same time, i need input for a push button,

tell me how to do...

any suggestion about when i push the button, it will not affect the led either on or off?

pin-->resistor-->led--> +5v

at the same pin, it will connect to a push button also.
Crying or Very sad
rnielsen



Joined: 23 Sep 2003
Posts: 852
Location: Utah

View user's profile Send private message

PostPosted: Tue Jul 24, 2007 8:30 am     Reply with quote

I've wished I could use a pin as an output and input at the same time too but, due to physics, I really don't believe that it's possible to have a pin do both at the same time. It is possible to have a pin alternate between the two, being an input at one moment and then change to be an output another moment, but it's just not possible to be both at the same time.

You'll need to change your design or use a PIC with more I/O. I'm sure many of the folks here have run out of pins and had to re-do things. But, if you find out how to accomplish what you're looking for post it here. I'm sure we'd all like to know how to do it. We could end up doubling the I/O that is available on each PIC. Wink

Ronald
SherpaDoug



Joined: 07 Sep 2003
Posts: 1640
Location: Cape Cod Mass USA

View user's profile Send private message

PostPosted: Tue Jul 24, 2007 8:57 am     Reply with quote

You might be able to do something if you can flash or PWM the LED. Connect a small capacitor (something like 0.01uf) from the PIC pin to the switch, and the switch to GND. If the switch is closed the LED and resistor will charge the cap to 5V in some amount of time determined by the resistor and capacitor values. If you turn on the LED briefly, but too brief to see, the cap will get discharged. Then make the PIC pin an input, wait a short time, and read the pin. If the switch is open the pin voltage will quickly return to 5V and you will read a "1". With the switch closed the pin voltage will rise more slowly and if the timing is right you will read a logic "0". The rest of the time you can use the pin to turn the LED on or off as required.

Working out the correct R, C, and timing is left as an exercise for the student.

T(seconds) = R(Ohms) x C(Farads)
_________________
The search for better is endless. Instead simply find very good and get the job done.
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