Creating your own .inc files


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

    Default Creating your own .inc files

    HELP!! I want to create some of my own library files of some sub-routes that I use quite often. This would help me from having to rewrite things over and over. I tried just creating an .inc file with these sub-routes and then including that .inc file in my main file but it is not working. Can anyone help me set this up? Thanks

  2. #2
    Join Date
    Feb 2006
    Location
    Gilroy, CA
    Posts
    1,530


    Did you find this post helpful? Yes | No

    Default

    http://www.picbasic.co.uk/forum/showthread.php?t=2108

    I use includes like this:

    Code:
    'main .pbp code here
    INCLUDE "INC_SUB.INC"
    'define variables for main .pbp
    start:    'place for include file to return to
    
    'etc etc ... all code below
    
    gosub sub_a
    
    gosub sub_b
    Then in INC_SUB.INC
    Code:
    'define variables for INC_SUB.INC (whatever your include file is called)
    goto start    'this jumps back to the beginning of your main .pbp file. 
                  'otherwise it would start to try to run your subroutines at power up
    'all your subroutines below here
    sub_a:
    'a code goes here
    
    return
    
    sub_b:
    'b code goes here
    return
    probably a better way to do it, but it works.
    Last edited by ScaleRobotics; - 26th May 2009 at 17:10.
    http://www.scalerobotics.com

  3. #3
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Hi Walter,

    Just a note about your includes.
    Each Include file should jump over it's own subroutines, but not to the main program.
    The Include has no idea where the Start label is, and may be jumping over other Include files or important code.

    By jumping over only the code in the Include itself, it can't interfere with anything else.

    Code:
    'define variables for INC_SUB.INC (whatever your include file is called)
    goto OverINC_SUB    'this jumps over the include file. 
                  'otherwise it would start to try to run your subroutines at power up
    'all your subroutines below here
    sub_a:
    'a code goes here
    
    return
    
    sub_b:
    'b code goes here
    return
    OverINC_SUB
    I've written quite a few Includes already, and found that when writing them for other people to use,
    the following format with three sections in the Include file seems to work the best.
    • Constants and Variables used by the module, should be declared in the module.
    • An Initialization section that runs on power-up and resets.
    • And the Subroutines, that get Jumped over.
    Code:
    <font color="#0000FF"><b><i>'****************************************************************
    '*  Name    : IncludeTemplate.pbp                               *
    '*  Author  : Darrel Taylor                                     *
    '*  Date    : 5/26/2009                                         *
    '****************************************************************
    
    ;---[Variables Aliases and Constants]---------------------------------------
    </i></b></font><b>Result    </b><font color="#008000"><b>VAR WORD </b></font><font color="#0000FF"><b><i>; Global Variables that will be used in the Main program
    </i></b></font><b>ModInput  </b><font color="#008000"><b>VAR BYTE </b></font><font color="#0000FF"><b><i>; should have easy to remember names.
    ;------------------
    </i></b></font><b>INC_VarA  </b><font color="#008000"><b>VAR WORD </b></font><font color="#0000FF"><b><i>; Local variables that are only used in the Include
    </i></b></font><b>INC_VarB  </b><font color="#008000"><b>VAR BYTE </b></font><font color="#0000FF"><b><i>; should have unique names that are unlikely to be 
    </i></b></font><b>INC_Const </b><font color="#008000"><b>CON </b></font><font color="#800000"><b>150  </b></font><font color="#0000FF"><b><i>; duplicated by the user, or other Includes.
    
    ;---[Initialize the INCLUDE module]-----------------------------------------
    </i></b></font><b>INC_VarA </b>= <font color="#800000"><b>0       </b></font><font color="#0000FF"><b><i>; This section will run on power-up or reset.
    </i></b></font><b>INC_VarB </b>= <font color="#800000"><b>100     </b></font><font color="#0000FF"><b><i>; inititialize any registers needed for this module,
    </i></b></font><b>Result   </b>= <font color="#800000"><b>0       </b></font><font color="#0000FF"><b><i>; dont rely on the user to initialize values (they won't)
    
    </i></b></font><font color="#008000"><b>GOTO </b></font><b>OverINC_SUBS  </b><font color="#0000FF"><b><i>; jump over Subroutines, so they don't try to execute
    ;---[Subroutines]-----------------------------------------------------------
    </i></b></font><b>Sub_A</b>:
        <b>Result </b>= <b>ModInput </b>* <b>INC_VarA</b> + <b>INC_Const
    </b><font color="#008000"><b>RETURN
    </b></font><font color="#0000FF"><b><i>;----------------------------
    </i></b></font><b>Sub_B</b>:
        <b>Result </b>= <b>ModInput </b>* <b>INC_VarB</b> + <b>INC_Const
    </b><font color="#008000"><b>RETURN
    
    </b></font><font color="#0000FF"><b><i>;---------------------------------------------------------------------------
    </i></b></font><b>OverINC_SUBS</b>:      <font color="#0000FF"><b><i>; This label must be unique for each Inlude file
    </i></b></font>
    HTH,
    DT

  4. #4
    Join Date
    Feb 2006
    Location
    Gilroy, CA
    Posts
    1,530


    Did you find this post helpful? Yes | No

    Default

    Thanks Darrel,

    That is a lot better, and would have eliminated the trouble shooting problem I had with A/D conversion a while back.
    http://www.scalerobotics.com

  5. #5


    Did you find this post helpful? Yes | No

    Talking Thank you

    Thank you!! I didn't realize that it tried to run the code at startup. I added my "jump over" and it works perfect now.

    Thank you very much!!!!

Similar Threads

  1. Compiler not creating .hex files for programmer.
    By Teknikum in forum mel PIC BASIC Pro
    Replies: 11
    Last Post: - 15th May 2009, 10:37
  2. Bootloader files for MicroCode Studio Plus
    By keithdoxey in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 30th December 2007, 18:54
  3. Missing 16F882 family include files :-(
    By campmdabt in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 27th December 2007, 01:17
  4. Replies: 2
    Last Post: - 13th December 2005, 00:11
  5. How can I find Code Loader 18F2620 files ?
    By muskut in forum General
    Replies: 1
    Last Post: - 14th October 2005, 12:26

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