View Full Version : Outside the Mainloop
pescador
- 23rd April 2016, 12:49
First post - first program - I want to initialize some variables before the mainloop executes and have subroutines below the mainloop controlled by gosubs within the mainloop. The problem I've been seeing is the gosubs seems to execute without being called, for example a initialize the variables sub routine, like the program kept going instead of returning to the top of the mainloop. Do I need an "end" after goto mainloop?
for example
gosub init:
MAINLOOP:
if x = 2 then
gosub dothis
endif
goto mainloop
dothis:
program
return
init:
x = 1
return
I've seen the dothis sub routine get executed without gosub being executed...like the program just keeps going past the goto mainloop command - (crude example of my real program)
I'm wondering if I'm missing a golden rule of keeping my program flow within the mainloop.
HenrikOlsson
- 23rd April 2016, 18:15
Hi,
Except for the colon in the line GOSUB Init: I don't see any issues with this piece of code. Make sure ALL subroutines ends with a RETURN. If you GOTO something FROM a subroutine then makes sure THAT piece of code ends with a RETURN. That's all the advice I can give you ATM.
You'd be much better helped if you boil down your ACTUAL code to something small that still shows the error and post that.
/Henrik.
Demon
- 23rd April 2016, 19:46
I used to write like you, except with the END as commented by Henrik.
I have since changed to how I've seen countless examples here:
Define variables and stuff
GOTO ProgramStart
Subroutine1:
bla bla
RETURN
ProgramStart:
bla bla
GOSUB Subroutine1
GOTO ProgramStart
END
Your code "should" work. But I've never had a freaky situation by coding like this yet.
Robert
Charlie
- 24th April 2016, 13:44
GOSUB init not GOSUB init: (which would then be a label)
MAINLOOP and mainloop are different things.
Post your actual code and we will help you find the other (likely) typos.
HenrikOlsson
- 24th April 2016, 15:31
MAINLOOP and mainloop are different things
No, they're not in this case. PBP is not case sensitive.
/Henrik.
pescador
- 24th April 2016, 23:44
ok - thanks - I will... I'm currently trying to HPWM a set of LEDs with a 12F683 next so I'll give that shot. I havea degree in CS - JAVA and C++, but haven't used it since college. I'm 60 years old this year - not kidding.. never too late.
Charlie
- 25th April 2016, 00:13
I stand corrected - labels are not case sensitive. Most other things are, however.
HenrikOlsson
- 25th April 2016, 06:15
Hi Charlie,
I'll elaborate a bit further: PBP is not case sensitive. The case of labels, commands, variables, constants, modifiers doesn't matter - not case sensitive.
It's only the case of the "things" that gets passed directly to the assembler (like anything coming after the keyword DEFINE or if you're using inline assembly) that matters because the assembler (MPASM(X)) IS case sensitive.
/Henrik.
Charlie
- 26th April 2016, 14:38
I checked the manual twice and it agrees with you, however I distinctly remember fixing a bug where I had mixed up capitalized variables and non-capitalized variables. (and I don't think it being passed to the assembler) Nevertheless, sorry for giving bad advice. In this case good form and good function are not necessarily related :-)
Dave
- 26th April 2016, 16:23
You may be thinking about the DEFINE commands. They need to be capitolized.
Demon
- 26th April 2016, 17:34
Actually, as Henrik has pointed out elsewhere, the DEFINE does not have to be capitalized, only the variables after it.
Robert
Powered by vBulletin® Version 4.1.7 Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.