Hello all,

I have been looking at this code for a couple of days. No matter how I rewrite it I get the same problem. This is what it is supposed to do....

sequence of button activations:

1). start button, goes low when pressed, I have 10K pullup on port.
2). Limit reached leaf switch, goes low when activated, 10K pullup on port.
3). optical phototransistor, 40K on collector, IR emitter cranking out a strong signal no issues on scope. Set up as basic breakbeam. works flawlessly.

What happens is the start button activation works, the limit leaf switch activation works, then it gets hosed on the optical switch. Nothing happens, in fact it looks like it vectors back to a part of the code that it should never revisit again except on power up. When I remove the leaf switch code, everything works including the optical switch. This is very confusing....HELP!!!

Code is below.


INCLUDE "Modedefs.Bas"
@ device pic16F877A, HS_OSC, LVP_OFF, WDT_OFF
PROTECT_OFF


DEFINE OSC 20


;set ports to output
TRISA = %00001111
TRISB = %00000111
TRISC = %00000000
TRISD = %00000000

; analog portA direction
ADCON1 = 7
CMCON = 7


;constants
brake Con %00000011
stmot con %00000000
runmot con %00000001

;variables
timeout var byte

;initialization
portc = stmot



checkOn:
if portb.0 = 1 then
goto checkon
else
portc = runmot
endif

main:
gosub checkLeaf
gosub checkopt
goto main


checkleaf:
if portb.1 = 0 then
portc = brake
pause 500
portc = stmot
else
goto checkleaf
endif
return

checkopt:
if portb.2 = 1 then
portc = runmot
else
goto checkopt
endif
return

end