PDA

View Full Version : Use of INCLUDE



Alexey
- 14th December 2013, 17:42
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

Demon
- 14th December 2013, 17:49
What thread title do you want? I can fix it.

Robert

HenrikOlsson
- 14th December 2013, 19:02
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.


' This will work
Test VAR BYTE
Test = 5


' This will not work
Test = 5
Test VAR BYTE

/Henrik.

Alexey
- 14th December 2013, 19:28
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

Archangel
- 15th December 2013, 06:23
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 regardsPerhaps this ?
MyVar VAR WORD bankx where x is the memory bank you want your var in ?

Alexey
- 16th December 2013, 02:16
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

Heckler
- 16th December 2013, 15:29
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.

Alexey
- 23rd December 2013, 04:15
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

Art
- 25th December 2013, 13:51
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.