
Originally Posted by
forgie
With the LCD example, I was actually thinking more along the lines of how would one get a macro that can handle a list of arguments, like LCDOUT does.
Well, I thought that's what it does. It takes a list of arguments, but instead of using commas, it uses the Plus sign instead.
Take a look at this thread Embedded Strings in your Code Space
It has some more examples of passing parameters with macro's.
But really, the main problem is that MPASM always has to have the exact number of parameters supplied to a macro. So a single macro can't accept 2 parameters on 1 use and 5 on another. PM has that ability, but I don't like making programs that only work with PM since you can't use it with the 18F's

Originally Posted by
forgie
Is it possible to do for loops in macros? e.g. make a macro called LCDRIGHT x which moves the cursor right x spaces, and define it using a for loop?
Yes, you can do that. But keep in mind that every time you use a macro, it duplicates the entire code at the place where it is used. So, big macro's that are used several times can eat up a lot of code space. There are ways around that too, but it's not for the scardy cats. For instance, consider this example as an alternative to the LCDRIGHT idea. It allows you to move the cursor anywhere on the screen using either constants or byte variables. Using the constant version would look like this
Code:
@ LCDCUR?C 1,5 ; Row, Col
Which would move the cursor to Row1, Colomn5.
Or, using the byte variable version would be like this
Code:
Row VAR BYTE system
Col VAR BYTE system
Row = 2
Col = 10
@ LCDCUR?B Row, Col
Here's the macros for them. They are self optimising, so that no code is generated unless you actually use them. The main parts of the routine are actually subroutines that can be "called", and the macros you use in the main program simply place the parameters in Temp variables so that the "called" routine can access them. This way it only uses a few words each time you use one of the macro's.
Code:
This code has been removed, please see a couple posts down for the revision.
Should have tested it first. Doh!
I just threw this together last night in anticipation of your next question, so if you actually try it, and have problems, let me know.
Best regards,
Darrel
Bookmarks