Making PBP code more modular


Results 1 to 31 of 31

Threaded View

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


    Did you find this post helpful? Yes | No

    Default

    You might want to try making includes NOT processor specific. Otherwise you go back to that multiple version problem again. If you need a new file for every chip you use, you'll be writing include files for ever.
    is there any way to make a macro in asm, then put PBP code inside the macro?
    Sure, you can pop in and out of asm whenever you want, but passing arguments can be a little trickier. Let's go back to the first example
    Code:
    ASM
    TMR1_ON  macro
        bsf  T1CON, TMR1ON
        endm
    
    TMR1_OFF  macro
        bcf  T1CON, TMR1ON
        endm
    ENDASM
    This could also be done this way
    Code:
    ASM
    TMR1_ON  macro
        ENDASM
        T1CON.0 = 1     ' PBP statement in a macro
        ASM
        endm
    
    TMR1_OFF  macro
        ENDASM
        T1CON.0 = 0
        ASM
        endm
    ENDASM
    But, as you can see, it's harder to read that way, but will compile to the exact same thing.
    so that LCDCMD Clear, Line1, Right would have the effect of LCDOUT $FE, $01, $FE, $80, $FE, $14
    Let's try the LCD thing with PBP statements too. This may not be the most efficient way to handle the LCD, but it does answer the specific question...
    Code:
    Clr       CON    1  system
    Home      CON    2  system
    Line1     CON    4  system
    Line2     CON    8  system
    Line3     CON   16  system
    Line4     CON   32  system
    CurOFF    CON   64  system
    CurBlink  CON  128  system
    CurUL     CON  256  system
    
    ASM
    LCDCMD  macro  options
        if (options & Clr) > 0      ; Clear Screen
            ENDASM
            LCDOUT  $FE, $01
            ASM
        endif
        if (options & Home) > 0     ; Home Cursor
            ENDASM
            LCDOUT  $FE, $02
            ASM
        endif
        if (options & Line1) > 0    ; Move to Line 1
            ENDASM
            LCDOUT  $FE, $80
            ASM
        endif
        if (options & Line2) > 0    ; Move to Line 2
            ENDASM
            LCDOUT  $FE, $C0
            ASM
        endif
        if (options & Line3) > 0    ; Move to Line 3
            ENDASM
            LCDOUT  $FE, $90         ; may be $94 on some displays
            ASM
        endif
        if (options & Line4) > 0    ; Move to Line 4
            ENDASM
            LCDOUT  $FE, $D0         ; may be $D4 on some displays
            ASM
        endif
        if (options & CurOFF) > 0   ; Turn Off Cursor
            ENDASM
            LCDOUT  $FE, $0C
            ASM
        endif
        if (options & CurBlink) > 0 ; Blinking Cursor
            ENDASM
            LCDOUT  $FE, $0F
            ASM
        endif
        if (options & CurUL) > 0    ; Underline Cursor
            ENDASM
            LCDOUT  $FE, $0E
            ASM
        endif
        endm
    ENDASM
    Then to use the macro you can do it this way...
    Code:
    @ LCDCMD Clr + CurBlink       ; Clear screen and turn on blinking cursor
    '-- OR --
    @ LCDCMD Clr + Line2 + CurOFF ; Clr screen, Move to Line2 and turn off cursor
    Any of the options can be combined together, and only the options you use will actually create code.

    HTH,
       Darrel
    Last edited by Darrel Taylor; - 27th July 2005 at 07:51.

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