On Mon, 9 Jun 1997, Glen Benson wrote: > Hi, > > Im fairly new to pics, so if this is a dumb question please ignore it. > I am using basic until i learn asm, and I noticed that if I close a > momentary switch to bring an input pin high, it stays high for some time > (approx. 15 seconds) then it will go low. I can set the pin low just after > the pin goes high, but that doesnt alow me to see if the button is being > held down. Below is some sample code. Is there a way to keep the pin from > latching high for so long? > > Any help appreciated. > > 16c84 > > '---------- begin code ------------- > input pin0 ' make pin 0 an input > start: if pin0=0 then start ' loop until button pressed > > action: high 7 ' turn on an led (or whatever) > > wait: if pin0=1 then wait ' wait for pin 0 to go low > goto start ' go back and wait for button again > '--------------- end code --------------- > > The above code will loop on the wait label for about 8 seconds ( I didnt > time it, But it was too long to be useful. If force pin0 low at the first > line of the action label, it works but I cant tell if the button is held down. > > Thanks > > Glen Benson > The problem you may be facing is with the circuitry itself, you mention a momentary switch but no tie down or pull up resistors. If you have a switch pulling the input to high, make sure you also have a resistor pull the input to low. This way you wont have to wait for the charge to "leak out" of the input pin. This works the opposite as well, ie. if you have a switch to pull the input lo, have a resistor pulling the pin high. this will also eliminate possible false switching due to the pin floating while the switch is open, another alternative is to use the internal weak pull up option if using port B. | --- pin o----0 0----o +5v | / \ approx example of pull down resistor / 5-10k | o ground