Making PBP code more modular


Results 1 to 31 of 31

Threaded View

  1. #17
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Quote 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

    Quote 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
    Last edited by Darrel Taylor; - 28th July 2005 at 07:42.

Similar Threads

  1. PBP Extensions, What are they?
    By PJALM in forum PBP Extensions
    Replies: 9
    Last Post: - 28th September 2021, 11:26
  2. PBP code to read R/C signal from receiver
    By malc-c in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 28th October 2009, 21:51
  3. Making Program Code Space your playground...
    By Melanie in forum Code Examples
    Replies: 15
    Last Post: - 19th July 2008, 08:26
  4. 4 Chanel Dmx512 ready assembly code to PBP ?
    By syscoder in forum mel PIC BASIC Pro
    Replies: 10
    Last Post: - 21st March 2007, 23:55
  5. convert code "c" lcd graphic to pbp
    By nicolasronan in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 19th June 2006, 15:49

Members who have read this thread : 1

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