Making PBP code more modular


Results 1 to 31 of 31

Threaded View

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


    Did you find this post helpful? Yes | No

    Default

    OK, so that last example was terrible. Should have tested it first.

    Here's a better one that shows more of how to use PBP statements in macro's. It's also a little easier to see how the "self optimization" works. (this time I tested it)
    Code:
    <b>DEFINE  </b></font><b>LCDCOLS 16  </b><font color="#0000FF"><b><i>; can be 8, 16, 20, 24 or 40
                        ; but 20 is the only one that matters in this routine
    </i></b></font><b>LCD_Row   </b><font color="#008000"><b>VAR BYTE </b></font><b>system
    LCD_Col   </b><font color="#008000"><b>VAR BYTE </b></font><b>system
    
    </b><font color="#008000"><b>ASM
        </b></font><font color="#000080">ifndef LCDCOLS
            #define LCDCOLS 16    </font><font color="#0000FF"><b><i>; Default to 16 Columns
        </i></b></font><font color="#000080">endif
    
    MoveCursorExpanded = 0
    
    
    </font><font color="#0000FF"><b><i>; --- Move cursor to new location ---(inputs are LCD_Row and LCD_Col)-----------
    </i></b></font><font color="#000080">Expand_MoveCursor  macro
      local  OverCode
        goto      OverCode
    MoveCursorExpanded = 1
    MoveCursor
        if LCDCOLS == 20          </font><font color="#0000FF"><b><i>; if using a 4x20 display
            </i></b></font><font color="#008000"><b>ENDASM
                LOOKUP </b></font><b>LCD_Row</b>,[<b>$80</b>,<b>$80</b>,<b>$C0</b>,<b>$94</b>,<b>$D4</b>],<b>LCD_Row
            </b><font color="#008000"><b>ASM
        </b></font><font color="#000080">else                      </font><font color="#0000FF"><b><i>; if NOT using a 4x20 display
            </i></b></font><font color="#008000"><b>ENDASM
                LOOKUP </b></font><b>LCD_Row</b>,[<b>$80</b>,<b>$80</b>,<b>$C0</b>,<b>$90</b>,<b>$D0</b>],<b>LCD_Row
            </b><font color="#008000"><b>ASM
        </b></font><font color="#000080">endif
        </font><font color="#008000"><b>ENDASM
            </b></font><b>LCD_Row </b>= <b>LCD_Row </b>+ (<b>LCD_Col </b>- <b>1</b>)
            <font color="#008000"><b>LCDOUT </b></font><b>$FE</b>, <b>LCD_Row  </b><font color="#0000FF"><b><i>; Send the command
        </i></b></font><font color="#008000"><b>ASM
        </b></font><font color="#000080">return
    OverCode
        endm
    
    </font><font color="#0000FF"><b><i>; --- Move LCD cursor to  Row, Column using constants --------------------------
    </i></b></font><font color="#000080">LCDCUR?C  macro  Row, Col
        if MoveCursorExpanded == 0
            Expand_MoveCursor
        endif
        MOVE?CB   Row, LCD_Row
        MOVE?CB   Col, LCD_Col
        L?CALL    MoveCursor
        endm
    
    </font><font color="#0000FF"><b><i>; --- Move LCD cursor to  Row, Column using Byte variables ---------------------
    </i></b></font><font color="#000080">LCDCUR?B  macro  Row, Col
        if MoveCursorExpanded == 0
            Expand_MoveCursor
        endif
        MOVE?BB   Row, LCD_Row
        MOVE?BB   Col, LCD_Col
        L?CALL    MoveCursor
        endm
    
    </font><font color="#008000"><b>ENDASM
    </b></font>
    Using them is still the same
    Code:
    <font color="#000080">@ LCDCUR?C 1,5          </font><font color="#0000FF"><b><i>; Move to Row1 Column5
      </i></b></font><font color="#008000"><b>LCDOUT </b></font><font color="#FF0000">&quot;R1C5&quot;         </font><font color="#0000FF"><b><i>; Display something
    
    '-- OR --
    
    </i></b></font><b>Row  </b><font color="#008000"><b>VAR BYTE  </b></font><b>system
    Col  </b><font color="#008000"><b>VAR BYTE  </b></font><b>system
    
    Row </b>= <b>2
    Col </b>= <b>10
    </b><font color="#000080">@ LCDCUR?B  Row, Col    </font><font color="#0000FF"><b><i>; Move to Row2 Column10
      </i></b></font><font color="#008000"><b>LCDOUT </b></font><font color="#FF0000">&quot;R2C10&quot;        </font><font color="#0000FF"><b><i>; Display something</i></b></font>
    Last edited by Darrel Taylor; - 29th July 2005 at 09:43.
    DT

Similar Threads

  1. PBP Extensions, What are they?
    By PJALM in forum PBP Extensions
    Replies: 9
    Last Post: - 28th September 2021, 12: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, 22:51
  3. Making Program Code Space your playground...
    By Melanie in forum Code Examples
    Replies: 15
    Last Post: - 19th July 2008, 09:26
  4. 4 Chanel Dmx512 ready assembly code to PBP ?
    By syscoder in forum mel PIC BASIC Pro
    Replies: 10
    Last Post: - 22nd March 2007, 00:55
  5. convert code "c" lcd graphic to pbp
    By nicolasronan in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 19th June 2006, 16: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