hello, i wrote a program for pic16F876 to do the following:

press button RB7 and led RB1 wil go on and stay on no matter how long you push RB7.
if you release RB7 the led RB1 will stay on,
if you push the RB7 again, the led will go off again , no matter how long you push RB7

This works perfectly standalone, but when i put it in a SUB and call it from the main, it doesn't work properly anymore,
So push RB7 gosub flipflop, push RB6 gosub onoff (turn led B0 on).
I used pulldown resistors, so that ain't the problem

I'm puzzled:

here is the working program:


trisb=%11110000
yy var byte
yy=2
portb=0

start:


if yy=2 and portb.7=0 then
yy=10
endif

if yy=10 and portb.7=1 then
yy=20
portb.1=1
endif

if yy=20 and portb.7=0 then
yy=30
endif

if yy=30 and portb.7=1 then
yy=40
portb.1=0
endif

if yy=40 and porta.7=0 then
yy=2
endif

goto start


'------------------------------

and now the subroutine version (Can't get it to work!!)


trisb=%11110000
yy var byte
yy=2
portb=0
start:

if portb.7=1 then
gosub flipflop
endif

if portb.6=1 then
gosub onoff
else
portb.0=0
endif

goto start


flipflop:
if yy=2 and portb.7=0 then
yy=10
endif

if yy=10 and portb.7=1 then
yy=20
portb.1=1
endif

if yy=20 and portb.7=0 then
yy=30
endif

if yy=30 and portb.7=1 then
yy=40
portb.1=0
endif

if yy=40 and porta.7=0 then
yy=2
endif

goto start

onoff:
portb.0=1
goto start

'===========================

Who can help me out here ???

greetz, Maus