"gosub" to lable in included file?


Closed Thread
Results 1 to 7 of 7
  1. #1

    Default "gosub" to lable in included file?

    Making seperate files so the main pb program file isn't so long and convoluted, and the subjects are more organized, then "including' on the main file......
    can I call a routine in another file from the main page with a "gosub"?
    '''''''''''''''''''''''''''''''''''''''''''''
    INCLUDE "TX_RX.pbp"

    on main pbp
    xxx
    yyy
    gosub 123 ''''in TX_RX file
    continue

    thanks, don
    amgen

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


    Did you find this post helpful? Yes | No

    Default Re: "gosub" to lable in included file?

    Hi,
    Yes you can, did you try it?
    The INCLUDE statement puts content of the included file exactly where you place the INCLUDE statement.

    /Henrik.

  3. #3


    Did you find this post helpful? Yes | No

    Default Re: "gosub" to lable in included file?

    Hi Henrik,
    yes, I must have left off the "return" or something, trying again it worked fine. But since I put the defines for the seperate file related variables in that file ( for example the tx and rx variable names etc) , then that "include" had to be left at the top of the main.
    Calls to subroutines on that file do work, but I am wondering where those routines get placed into the compiled program or mabye it doesn't matter ?

    don

  4. #4
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,521


    Did you find this post helpful? Yes | No

    Default Re: "gosub" to lable in included file?

    They get placed, line by line, exactly where you put the INCLUDE statement. If you you have variables declared inside the included file which you are trying to use "before" actually including the file you'll get errors.

    If the following is placed in an include file
    Code:
    myVAR   VAR  BYTE
    TestIt:
      HSEROUT["This is a test",13]
      High PortB.0
    RETURN
    And your complete program looked like this:
    Code:
    INCLUDE "myIncludeFile.pbp"
    Start:
      Low PortB.0
      GOSUB TestIt
      Pause 1000  
      Goto Start
    It would be exactly the same as
    Code:
    myVAR   VAR  BYTE
    TestIt:
      HSEROUT["This is a test",13]
      High PortB.0
    RETURN
    Start:
      Low PortB.0
      GOSUB TestIt
      Pause 1000  
      Goto Start
    See? The INCLUDE statements just takes the content of the file and places it, line by line, "inplace" of the actual INCLUDE statement - that's it.

  5. #5


    Did you find this post helpful? Yes | No

    Default Re: "gosub" to lable in included file?

    OK, then it seems that, that would/could throw your main program out-of-wack if you don't realize the includes stuff was placed in the main program first (if that is where they were placed).
    Then to place any runnable code , intended to be used as subroutines , in included files, should be:

    'TX_RX file

    var1 var byte
    var2 var word
    etc

    goto around_code

    code and subs to be called later......

    around_code

    ????
    don

  6. #6
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,521


    Did you find this post helpful? Yes | No

    Default Re: "gosub" to lable in included file?

    Yes, you need to jump over the subroutines in order for them not to execute as the PIC starts up - exactly as you would if you literally placed your subroutines at the top of the program. There's really no difference. INCLUDE just puts whatever is in the included file, exactly the way it is in the file, exactly at the spot of the INCLUDE statement.

    I usually create a file containing all my subroutines, at the beginning of it I have a GOTO OverSubroutines and at the very end I have a label OverSubroutines:
    If I have "local" variables used only internally by the subroutines I usually declare them in the subroutines file instead of in the main program file.

    You can definitely have the INCLUDE statment after the END of the main program in which case the subroutines will be place there and you don't need to jump around them. But then, if something in the main program tries to access variables you have declared IN the included file you'll get errors because those variables doesn't exist to as the compiler parses thru the source code again exactly as would be the case if you literlly put your variable declarations at the end of the source file.

    /Henrik.

  7. #7


    Did you find this post helpful? Yes | No

    Default Re: "gosub" to lable in included file?

    Henrik,Thankyou, good stuff.

    I will be gone over weekend but next week I would like to ask about making/organizing assorted tables, strings, arrays to be used to send different strings and data, mabye using dw or dt at program time and where to put things, flash, EEprom, ram for easy access etc.
    don

Members who have read this thread : 1

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