Knowledge Base

Example: Integer count display with OBLCD

This example gives you the chance to explore the differences between signed and unsigned integer numbers, and between fixed field width and variable field width integer formats.

We will make a program that uses the MMi99 front panel buttons to increment a number by 1 or by 10. The buttons will be assigned, from top to bottom, as “+10”, “+1”, 0 (clear the count), “-1” and “-10”. The resulting number will be displayed in all 4 integer formats. The screen layout will be:

0123456789012345 (ruler line)
UFW:999;SFW:-999
UVW:999;SVW:-999

For example, with the number 23 the display should be:

0123456789012345 (ruler line)
UFW: 23;SFW:  23
UVW:23 ;SVW:23  

In all cases the actual display field is bounded by punctuation marks or the end of the line. If you are using an LCD with more than 16 columns, take it as an exercise to modify the program to add a semicolon after the second number on each line.

Here is the program:

;Integer count on LCD. Example from onboard LCD documentation

iPlus10     iEQU  12
iPlus1      iEQU  11
iZero       iEQU  10
iMinus1     iEQU  9
iMinus10    iEQU  8
Counter       mEQU  0

     OBLCD_Type   2        ;initialize the LCD
Loop
     InputK       iPlus10  ;Test a button
     GoIfT        Add10
     InputK       iPlus1   ;Test a button
     GoIfT        Add1
     InputK       iZero    ;Test a button
     GoIfT        Clear
     InputK       iMinus10  ;Test a button
     GoIfT        Sub10
     InputK       iMinus1   ;Test a button
     GoIfT        Sub1
     GoTo         Loop

Add10
     Recall       Counter
     IncX
     IncX
     IncX
     IncX
     IncX
     IncX
     IncX
     IncX
     IncX
     IncX
     Store        Counter
     GoTo         Display

Add1
     Recall       Counter
     IncX
     Store        Counter
     GoTo         Display

Sub10
     Recall       Counter
     DecX
     DecX
     DecX
     DecX
     DecX
     DecX
     DecX
     DecX
     DecX
     DecX
     Store        Counter
     GoTo         Display

Sub1
     Recall       Counter
     DecX
     Store        Counter
     GoTo         Display

Clear
     SetMem       Counter,0
;Fall through
Display
     OBLCD_SetCur 0,0
;                 "0123456789012345"
     OBLCD_Text   "UFW:   ;SFW:    "
     OBLCD_SetCur 1,0
;                 "0123456789012345"
     OBLCD_Text   "UVW:   ;SVW:    "

     OBLCD_SetCur 0,4
     Recall       Counter
     OBLCD_UDecDispXFW


     OBLCD_SetCur 0,12
     Recall       Counter
     OBLCD_SDecDispXFW


     OBLCD_SetCur 1,4
     Recall       Counter
     OBLCD_UDecDispXVW


     OBLCD_SetCur 1,12
     Recall       Counter
     OBLCD_SDecDispXVW

     GoTo         Loop