Outside the Mainloop


Closed Thread
Results 1 to 11 of 11
  1. #1
    Join Date
    Apr 2016
    Location
    Plainfield, Illinois
    Posts
    73

    Default Outside the Mainloop

    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.

  2. #2
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,520


    Did you find this post helpful? Yes | No

    Default Re: Outside the Mainloop

    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.

  3. #3
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    2,597


    Did you find this post helpful? Yes | No

    Default Re: Outside the Mainloop

    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:

    Code:
    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
    My Creality Ender 3 S1 Plus is a giant paperweight that can't even be used as a boat anchor, cause I'd be fined for polluting our waterways with electronic devices.

    Not as dumb as yesterday, but stupider than tomorrow!

  4. #4
    Join Date
    Dec 2010
    Posts
    409


    Did you find this post helpful? Yes | No

    Default Re: Outside the Mainloop

    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.

  5. #5
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,520


    Did you find this post helpful? Yes | No

    Default Re: Outside the Mainloop

    MAINLOOP and mainloop are different things
    No, they're not in this case. PBP is not case sensitive.

    /Henrik.

  6. #6
    Join Date
    Apr 2016
    Location
    Plainfield, Illinois
    Posts
    73


    Did you find this post helpful? Yes | No

    Default Re: Outside the Mainloop

    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.

  7. #7
    Join Date
    Dec 2010
    Posts
    409


    Did you find this post helpful? Yes | No

    Default Re: Outside the Mainloop

    I stand corrected - labels are not case sensitive. Most other things are, however.

  8. #8
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,520


    Did you find this post helpful? Yes | No

    Default Re: Outside the Mainloop

    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.

  9. #9
    Join Date
    Dec 2010
    Posts
    409


    Did you find this post helpful? Yes | No

    Default Re: Outside the Mainloop

    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 :-)

  10. #10
    Join Date
    Mar 2003
    Location
    Commerce Michigan USA
    Posts
    1,166


    Did you find this post helpful? Yes | No

    Default Re: Outside the Mainloop

    You may be thinking about the DEFINE commands. They need to be capitolized.
    Dave Purola,
    N8NTA
    EN82fn

  11. #11
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    2,597


    Did you find this post helpful? Yes | No

    Default Re: Outside the Mainloop

    Actually, as Henrik has pointed out elsewhere, the DEFINE does not have to be capitalized, only the variables after it.

    Robert
    My Creality Ender 3 S1 Plus is a giant paperweight that can't even be used as a boat anchor, cause I'd be fined for polluting our waterways with electronic devices.

    Not as dumb as yesterday, but stupider than tomorrow!

Members who have read this thread : 2

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts