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)Using them is still the sameCode:<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>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">"R1C5" </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">"R2C10" </font><font color="#0000FF"><b><i>; Display something</i></b></font>




Bookmarks