View previous topic :: View next topic |
Author |
Message |
rajeshkhan808
Joined: 29 Aug 2012 Posts: 17
|
Why are all my pins high with set_tris_a(0xFF) -PIC 16f877A |
Posted: Thu Aug 30, 2012 2:07 am |
|
|
When I do set_tris_a(0xFF) for setting all the pins of port A on my PIC16F877A as input. They are all high. I thought they are still in analog mode.So I did the following
Code: |
setup_adc( ADC_OFF );
setup_adc_ports(NO_ANALOGS);
set_tris_a(0xFF); |
However they are still high. Why is that ?
Last edited by rajeshkhan808 on Thu Aug 30, 2012 2:30 am; edited 4 times in total |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19518
|
|
Posted: Thu Aug 30, 2012 2:21 am |
|
|
What PIC....
Normally:
setup_adc_ports(NO_ANALOGS);
but the syntax does change between chips.
Best Wishes |
|
|
rajeshkhan808
Joined: 29 Aug 2012 Posts: 17
|
|
Posted: Thu Aug 30, 2012 2:22 am |
|
|
Hi , thanks for the reply just edited the question. I am using PIC16F877A |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19518
|
|
Posted: Thu Aug 30, 2012 2:42 am |
|
|
Obvious thing is something external pulling them up....
Remember that a 'input' pin, has a very high impedance, and will sit for minutes, at the voltage it was last 'at', if nothing else is connected. It is up to whatever you connect externally to pull them to the required level.
Now, on some of the pins (A4, A5), you have the comparator outputs, so this needs to be disabled (setup_comparator(NC_NC_NC_NC)).
Best Wishes |
|
|
Mike Walne
Joined: 19 Feb 2004 Posts: 1785 Location: Boston Spa UK
|
|
Posted: Thu Aug 30, 2012 3:03 pm |
|
|
If you are still really stuck, post SHORT complete compilable code which shows the problem.
Also quote version No. and see forum guidelines.
Mike |
|
|
benoitstjean
Joined: 30 Oct 2007 Posts: 566 Location: Ottawa, Ontario, Canada
|
|
Posted: Fri Aug 31, 2012 6:07 am |
|
|
Put some 4.7K resistors on each pin to GND. That'll solve the problem. If you don't, then the pins somewhat act as "antennas" and will react to whatever it "captures" so just rubbing your finger on a pin will make it change state. If you connect a 4.7K to GND, then the inputs are pulled low and will remain low until you send it a high level. |
|
|
rajeshkhan808
Joined: 29 Aug 2012 Posts: 17
|
SOLVED |
Posted: Fri Aug 31, 2012 6:42 am |
|
|
@benoitstjean
Thanks that solved the problem |
|
|
|