Use of INCLUDE


Closed Thread
Results 1 to 9 of 9

Thread: Use of INCLUDE

  1. #1
    Join Date
    Dec 2009
    Location
    Canada
    Posts
    68

    Default Use of INCLUDE

    Hello All,

    sorry for misprint in the topic name - no way to correct too late

    Is there a way of definition of variables inside of the included file and use them in the main program before the INCLUDE? (I want to put INCLUDE in the end of the program to have it in the end of memory and still have it self sufficient, not requiring any external definitions of variables)

    Best regards
    Last edited by Alexey; - 14th December 2013 at 18:44.

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


    Did you find this post helpful? Yes | No

    Default Re: ise of INCLUDE

    What thread title do you want? I can fix it.

    Robert

  3. #3
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,517


    Did you find this post helpful? Yes | No

    Default Re: ise of INCLUDE

    Hi,
    No, INCLUDE will put the content of the file exactly where the INCLUDE statement is located. Variables must be prior to them being used.
    Code:
    ' This will work
    Test VAR BYTE
    Test = 5
    Code:
    ' This will not work
    Test = 5
    Test VAR BYTE
    /Henrik.

  4. #4
    Join Date
    Dec 2009
    Location
    Canada
    Posts
    68


    Did you find this post helpful? Yes | No

    Default Re: ise of INCLUDE

    Thank you Gentlemen,

    Demon, I wished to name it "Use of INCLUDE" but my finger is too thick for the keyboard

    Yes, I agree, declaration of variables before use leaves less room for errors, although makes a bit less flexible use of Includes. Probably I will split them into two. like include1_header.pbp and include1_main.pbp for not placing seldom used code into the first page of memory

  5. #5
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default Re: Use of INCLUDE

    Quote Originally Posted by Alexey View Post
    Hello All,

    sorry for misprint in the topic name - no way to correct too late

    Is there a way of definition of variables inside of the included file and use them in the main program before the INCLUDE? (I want to put INCLUDE in the end of the program to have it in the end of memory and still have it self sufficient, not requiring any external definitions of variables)

    Best regards
    Perhaps this ?
    MyVar VAR WORD bankx where x is the memory bank you want your var in ?
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  6. #6
    Join Date
    Dec 2009
    Location
    Canada
    Posts
    68


    Did you find this post helpful? Yes | No

    Default Re: Use of INCLUDE

    Hello Archangel,

    I meant if I use the variable in the beginning of my code then I have to put the include before that which will automatically put the whole large piece of code in the beginning of the program memory and my main cycle and interrupt handler will be pushed in further program memory pages which will make them working slower (switching pages) in favor of seldom used subroutine which will be sitting on the first page.

    Actually I do not know how long it takes switching pages. If this is just a couple of cycles than probably there is nothing to worry about... What do you think?

    Does putting variables in upper banks works same way for RAM (saving cycles on switching pages?) So far I used this option (for RAM bank) only once because of a glitch preventing my program to work normally until I switched a bank for one variable - not sure what was the problem but the problem went away after that.

    Best regards,

    Alexey

  7. #7
    Join Date
    Oct 2009
    Location
    Utah, USA
    Posts
    427


    Did you find this post helpful? Yes | No

    Default Re: Use of INCLUDE

    Alexey,

    You could just open up the include file and copy/paste the code into your main program and then re-arrange it all you want.
    Nothing says you have to keep it in a separate Include file.
    Dwight
    These PIC's are like intricate puzzles just waiting for one to discover their secrets and MASTER their capabilities.

  8. #8
    Join Date
    Dec 2009
    Location
    Canada
    Posts
    68


    Did you find this post helpful? Yes | No

    Default Re: Use of INCLUDE

    Yes, of course this is all possible.

    I was just wondering if it is possible to do one simple include in the place where I want to see the code of my library in memory and use the functions without doing any definitions of the variables and the answer is that you may have convenience of use or control of there the code is placed in memory or convenience of pasting library code in a form of one piece "include" but not both if you want to use variables before the "include".

    In most cases this is not a big deal - just put all includes on the top, unless you want your main cycle and interrupts work as fast as possible, then you start moving seldom used code down, play with clearwdt and so on and then you have to split includes or just copy pieces of it's content in two separate places.

    Again, this is not a big deal, only a matter of some convenience of having own library functions

  9. #9
    Join Date
    Aug 2003
    Posts
    985


    Did you find this post helpful? Yes | No

    Default Re: Use of INCLUDE

    My guess is the included source is going where it wants, and you have no say about it.
    Furthermore, I'll take a stab that the source for individual commands are ordered the same,
    no matter what order your program first calls them.

    Imagine you can push routines such as SERIN, PULSIN, DTMF.. out of the first page or RAM bank
    because you thought your code was more important.
    Now all of a sudden, a bunch of PBP's timed routines have to do bank/page switching
    and you find out it was you that had to accommodate those routines rather than the other way around.

    One trick you can do, is borrow some system variables if you can figure out when they are not being used.
    There are variables used only to transport your PBP vars to it's serial routine for example.
    Any other time your code is not executing a "serious" instruction, those system variables are sitting around doing nothing.

Similar Threads

  1. Where are all the INCLUDE files??
    By Heckler in forum General
    Replies: 3
    Last Post: - 13th September 2011, 09:27
  2. Include File problem
    By lerameur in forum mel PIC BASIC Pro
    Replies: 13
    Last Post: - 23rd March 2011, 18:44
  3. How to open INCLUDE file
    By SKOLS1 in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 26th January 2011, 18:50
  4. can't find include file!
    By jimbostlawrence in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 10th November 2009, 09:44
  5. Need to download Include files
    By laflam_p in forum Off Topic
    Replies: 2
    Last Post: - 2nd September 2009, 14:39

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