Jim Ruxton wrote: >Using 2 I/Os (RB0 and RB1 on a 16C505) I am trying >to drive two back to back LEDs and read a switch at the end of 2 long >wires . Each pin has a 470 ohm resistor in series with it and a .01 uF >cap shunted to ground after the resistor. At the end of the two long >wires there is a switch in series with a parallel combo. of a red and >a green led (pointed in opposite directions) and a 10K resistor. There >is also a 100k pullup at RB1. When I want to drive the back to back LEDs >( if the switch is closed) RB0 and RB1 are outputs . When I want to >read the switch RB0 outputs 0 and RB1 tries to read whether the switch >is closed ie. RB1 sees 1 if it is open , 0 if closed. >The wire I am driving(reading) is quite long approx. 300 ft. I am having > >troubles reading the switch.I can read the switch ok if I don't change >RB1 to an output . But thats no good because I have to be able to >switch the LEDs.I tried putting nops between my TRIS statements etc. A Jim: The first impression that I get is that you're not leaving enough time for the cable to charge up (if it's going to). If your cable is 50pF/ft and you have two 0.01uF effectively in series across this, you have ~0.02uF and 100K. The time constant is thus ~2msec. Combined with the fact that the cable may have to discharge completely, then recharge to the other polarity you should be allowing possibly 10 *milli* seconds before checking the input. The first thing I'd try is adding straight delay to your program. Good luck, Jim Nagy Elm Electronics ICs for Experimenters http://www.elmelectronics.com/