Re: Watching for pin High
Just to expand on what others have posted...
Below is a schematic (sorry about the ugly resistors) that shows two different ways of wiring to detect a change on a port pin.
First... with PortA.0 pulled high and a press on the button will cause a LOW or 0.
Second... with PortA.1 pulled LOW and a press on the button will cause a HIGH or 1.
The resistors can be 1K to 10K...

It makes no difference and is not necessary to pre-set the state of the pin you are trying to test by "make port.pin LOW or HIGH" as that is an OUTPUT function not an INPUT function.
The correct way is to choose one of the wiring options as illistrated, set the corresponding TRIS BIT for that port.pin to an INPUT or "1" and then test for the opposite state, which will indicate a change or button press.
Code:
TrisA= 000011 'set PortA.0 and PortA.1 as input
IF PortA.0=0 THEN 'do something here when PortA.0 changes
IF PortA.1=1 THEN 'do something here when PortA.1 changes
as shown below... it is also correct to test for a "0" by testing for "NOT" and it is also correct to test for a "1" as shown...
Code:
IF NOT PortA.0 then '(this code tests for a "0" or "LOW")
IF PortA.1 THEN ' (this code tests for a "1" or "HIGH"
I hope this helps...
PS... if you can not see the schematic image above, click on it.
Last edited by Heckler; - 16th October 2011 at 17:33.
Dwight
These PIC's are like intricate puzzles just waiting for one to discover their secrets and MASTER their capabilities.
Bookmarks