Hey, Alan! I'll bet you ANYTHING that your problem is noise-related! Since MPLAB doesn't have noise, it WOULD work there! Unless a switch is debounced in hardware, I NEVER use just one pulse to indicate switch closure (as your code seems to be doing) - I always look for at least 16 LOWs in a row (or at least 10 MS.), resetting my counter every time the switch input goes HIGH. Only then do I consider the button pushed and start looking for a release. To restate, usually I have other code running and the switch counter is only incremented when I go through the INPUT routine and find the switch input LOW (the counter is cleared on the first HIGH received). As I exit the INPUT routine, I check the counter - if it's 16 (as in this example), I flag the switch as closed. If it is GREATER than 16 (i.e. 17), I force it to a fixed value greater than 16 (i.e.24) and ignore the result. Yes, I work in HEX, where I'm most comfortable because I can do this with bit checks. This allows the rest of the code to process a single push by recognizing the SWITCH PUSHED flag, processing it, and then clearing the flag. If you only want to know when the switch was released, just set the PUSHED flag when you see a HIGH and the counter is 16 or greater! I only use this technique when I have only one or two inputs to check. There are MUCH more elegant methods available when you have a whole bank of switches to check (browse the PICLIST archive - there're WONDERFUL examples to be found there!). As a temporary fix, try putting an R-C network (as another poster suggested) on the switch & see if it clears up. If it does, then noise was your problem and you can start looking for the best way to fix it. Good luck! Dennis alan smith wrote: >Agree...change the $-1 to a real label. Have you used the debugger to single step and watch the PC to see where it might be getting lost at? Maybe pist the list file and take a look at how its setting up the addressing. > >John Piccirillo wrote:I'm having a tremendous problem with a simple program. It's gotten >bizarre. The program works in the MPLAB simulator but not running >on a 16F84 (I tried an old 16C84 with the same results). Here's two >fragments: one works in the code, the other doesn't. > >The following works: > >again: >btfsc PORTA, 4 ;check for button press - normal hi >goto again ;button not pressed >btfss PORTA, 4 ; check button released >goto $-1 >call debounce ;4 ms time delay > >The following does NOT work: > >again: >nop >nop >btfsc PORTA, 4 ;check for button press - normal hi >goto again ;button not pressed >btfss PORTA, 4 ;check button released >goto $-1 >call debounce > >however, using only one nop works. > >If posting the entire code would help, its not long, I'd be glad to do so. > >Any help is greatly appreciated. > >John- > > > > -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist