PDA

View Full Version : Creating your own .inc files



mjphillips1981
- 26th May 2009, 16:30
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

ScaleRobotics
- 26th May 2009, 16:50
http://www.picbasic.co.uk/forum/showthread.php?t=2108

I use includes like this:



'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


'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.

Darrel Taylor
- 26th May 2009, 22:28
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.


'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.

<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,

ScaleRobotics
- 27th May 2009, 03:41
Thanks Darrel,

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

mjphillips1981
- 27th May 2009, 12:46
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!!!!:):):)