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

Buttons , Internal pull up ?

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



Joined: 12 Apr 2013
Posts: 24

View user's profile Send private message

Buttons , Internal pull up ?
PostPosted: Sat Jun 22, 2013 11:47 am     Reply with quote

PIC16F877A and PIC18F4550.

Hello i have a PCB that i made , it already has 2 buttons with pullup resistors ( 5V-> 4.7K res-> Pin . When button is pressed it grounds the input. They work fine .

Anyway i had to recently add 3 more buttons . I have alot of available pin connectors to my board but they do not have 4.7k Pull up resistors.

I am trying to simplify the new 3 buttons and instead of waiting for 0, to wait for 1. If i connect 5V-> 4.7k -> to the pin , the pin gets logical 1 , but if i remove the connected 5V->4.7k the pin state continues to stay 1 until i ground the pin connector or touch it with hand. I have the buttons set_tris set for input for all the buttons, before my while true loop(the code for the buttons is inside the while(true)) .

What if i use output_low(PIN_Dx); from CCS manual i see it "Sets a given pin to the ground state". Will this change the tris and make it an output only pin? Do i need to set the tris initially for the pins i want to use as input for buttons.
How can i remove the state 1(5V) on a pin after i remove the 5V source, without having to ground it.


Thanks, i am so sorry if the above questions sound ignorant and noobish Smile
tojape



Joined: 14 Jan 2007
Posts: 20
Location: Hungary

View user's profile Send private message

Re: Buttons , Internal pull up ?
PostPosted: Sat Jun 22, 2013 1:20 pm     Reply with quote

Hi tcruise7771

output_low(pin) changes the direction of a pin (except when you use fast_io)
You do not need to set the tris for the pins that are used as input for buttons (except when you use fast_io)
Note:
"value = input_state(pin)" doesn't change the tris.
"value=input(pin)" function is different. It returns the state of the indicated pin. The method of I/O is dependent on the last USE *_IO directive. By default with standard I/O before the input is done the data direction is set to input.

IO handling is precisely described in the ccs compiler help. Read it first.

I wonder the reason why you want some of the buttons use differently than the rest. However, if your decision is to use a button which applies high level to a pin when it is pressed, you have to keep it low when the button is not pressed. If the input state changes when you touch it with hand it means that the pin is actually floating instead of being pulled to a definite level.
Now I'm only guessing what you want. A schematic and the relevant part of your code would be helpful.
_________________
The computer helps solving the problems which would have never arised without computers
temtronic



Joined: 01 Jul 2010
Posts: 9221
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sat Jun 22, 2013 2:17 pm     Reply with quote

You'll need either pullup or pulldown resistors on any pin used for an input from a button or switch. The resistor forces the pin to a known state opposite, to what you look for.
Also be aware of 'switch bounce', which the PIC 'sees' as multiple switch operations not just the one when you press it. This bounce can be minimized by a capacitor and/or software delays (typ. 10-50ms).

Since you already have pullups on a couple pins, I'd suggest doing the same for the other pins. That way you have the same hardware and logic for your project.


hth
jay
tcruise7771



Joined: 12 Apr 2013
Posts: 24

View user's profile Send private message

PostPosted: Sat Jun 22, 2013 6:46 pm     Reply with quote

Yes i am using:
but_C= input(PIN_C6) and then
while (input(PIN_C6) != but_C) {....
I know how the pull up resistor works, but my teacher mentioned to me that there is a way to use the internal pullup resistor for the pin, thought i did not found any information so far.

temtronic, that was my original thought of doing the same hardware design for the other pins, thought it would be nice if the PIC was able to pullup the floating pin.
Ttelmah



Joined: 11 Mar 2010
Posts: 19496

View user's profile Send private message

PostPosted: Sun Jun 23, 2013 12:59 am     Reply with quote

You make the comment that you have lots of pins.

First, read the data sheet.
This will tell you that Port C, does not have any internal resistor, but Port B does.
This applies on both your chips.

PORT_B_PULLUPS instruction.

Best Wishes
tcruise7771



Joined: 12 Apr 2013
Posts: 24

View user's profile Send private message

PostPosted: Sun Jun 23, 2013 11:41 am     Reply with quote

Ok hardware it is then. I am using port B for 8bit parallel communication for 128x64 display so port B is already used up Smile I have some pins from C available and alot of pins on port D, so i will set up hardware pullups there, Thanks 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