View previous topic :: View next topic |
Author |
Message |
tcruise7771
Joined: 12 Apr 2013 Posts: 24
|
Buttons , Internal pull up ? |
Posted: Sat Jun 22, 2013 11:47 am |
|
|
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](images/smiles/icon_smile.gif) |
|
![](templates/subSilver/images/spacer.gif) |
tojape
Joined: 14 Jan 2007 Posts: 20 Location: Hungary
|
Re: Buttons , Internal pull up ? |
Posted: Sat Jun 22, 2013 1:20 pm |
|
|
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 |
|
![](templates/subSilver/images/spacer.gif) |
temtronic
Joined: 01 Jul 2010 Posts: 9174 Location: Greensville,Ontario
|
|
Posted: Sat Jun 22, 2013 2:17 pm |
|
|
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 |
|
![](templates/subSilver/images/spacer.gif) |
tcruise7771
Joined: 12 Apr 2013 Posts: 24
|
|
Posted: Sat Jun 22, 2013 6:46 pm |
|
|
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. |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah
Joined: 11 Mar 2010 Posts: 19367
|
|
Posted: Sun Jun 23, 2013 12:59 am |
|
|
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 |
|
![](templates/subSilver/images/spacer.gif) |
tcruise7771
Joined: 12 Apr 2013 Posts: 24
|
|
Posted: Sun Jun 23, 2013 11:41 am |
|
|
Ok hardware it is then. I am using port B for 8bit parallel communication for 128x64 display so port B is already used up I have some pins from C available and alot of pins on port D, so i will set up hardware pullups there, Thanks ![Smile](images/smiles/icon_smile.gif) |
|
![](templates/subSilver/images/spacer.gif) |
|