mischl,
Well, since you said "what is exactly the definition of a macro...", this is the way the MPASM.hlp file defines it.But that doesn't really do justice to what you can do with them.Macros are user defined sets of instructions and directives that will be evaluated in-line with the assembler source code whenever the macro is invoked.
Macros consist of sequences of assembler instructions and directives. They can be written to accept arguments, making them quite flexible. Their advantages are:
Higher levels of abstraction, improving readability and reliability.Applications might include creating complex tables, frequently used code, and complex operations.
- Consistent solutions to frequently performed functions.
- Simplified changes.
- Improved testability.
Macro's are simply a way of grouping bits of code together, so that with a single command, you can place many lines of code in your program at the point where the command is used. And, since they can accept "Parameters", they can work a lot like "Functions" in other languages.
They are strictly assembly language directives, but since PBP converts your Basic code into assembly language before it is compiled, they work quite well with PBP too. In fact, the entire PicBasic language is built around macro's.
The biggest thing to remember is that each time you reference a macro, the Entire code contained in the macro is copied into the program. So if you use a macro 10 times in your program, you will use up ten times as much code space. That's not quite as bad as it sound though, because you can create normal subroutines in PBP that are "Called" by the macro (like a GOSUB), and then all the macro needs to do is pass the parameters to it like a "Function".
If you look at the LCDbar_INC.bas file from the BARgraph example, you can see how that works. The BARgraph macro is only there to pass the parameters to the "ShowBAR:" subroutine.<hr>INCLUDE files are similar in only one respect. They also place a group of code at the location that the INCLUDE statement is placed in your program. But, the similarities end there. INCLUDE files do not have to be Assembly language, they can be 100% PBP statements, or they can be a mix of PBP and ASM. They can NOT accept parameters. Macro's inside of Include files seems to be the most usefull combination though.
A good place to start might be with the MPASM.HLP file. Assuming you have MPASM installed on you computer.
On my computer the help file can be found here...C:\WINDOWS\Help\MPASM.HLP but some installations are different.
After that, start reading the "Instruction Set" section of the datasheet for the PIC you are using. They all have that section.
It's a little tough to grasp in the beginning, but once you catch on, all those things you thought couldn't be done with PicBasic, are suddenly within reach again.
HTH,
Darrel
PS. Stump, that's a nice use of includes, hadn't thought of that one.





Bookmarks