Example: Simple text display with OBLCD
This example displays a variable status message for some sort of washing machine (maybe an industrial parts washer). The machine can have the following states: Idle; filling; heating; washing; emptying; rinsing and cooling.
The status display “owns” the bottom line of a 2×16 LCD, i.e. row 1. We will write the display function as a self-contained subroutine. It will be called with a number in X that indicates the current machine status, i.e. dictates which message is to be displayed. The following table defines call arguments (X values) versus action or display message:
| X | Status | Comment |
|---|---|---|
| 0 | Initialize | Called only at startup to initialize LCD |
| 1 | Idle | |
| 2 | Filling | |
| 3 | Heating | |
| 4 | Washing | |
| 5 | Emptying | |
| 6 | Rinsing | |
| 7 | Cooling |
X=0 is special in that it initializes the LCD. It should be called only once, as it will result in the screen being erased, which could interfere with the “owners” of other lines of the LCD.
We need to plan exactly what we intend to display for each state, so we can be sure our messages will fit.
0123456789012345(ruler line)Status: IdleStatus: FillingStatus: HeatingStatus: WashingStatus: EmptyingStatus: RinsingStatus: Cooling
As luck would have it, the longest status word “Emptying” can fit together with “Status: “. Had that not been the case we would have had to think up some different words, or abbreviate or eliminate “Status: “.
One thing we must watch, though, is that some words are shorter, so we will make them all the same length by padding with spaces. That avoids one word being displayed with the remnants of a previous, longer word also showing, for example “Idling” or “Rinsing”.
We will also need a small amount of code to test the message display. To do this we use two front panel buttons on the MMi201 to count up and count down a memory variable “Status”, making sure to not go over 7 or under 0.
;Status message display example from onboard LCD documentation
;Start of test code vvvvvvvvvvvvvvvvvvvv
iUpKey iEQU 12
iDnKey iEQU 11
Status mEQU 0
Start
GoSub StatusDisplay ;initialize
SetMem Status,1
Loop
InputK iUpKey
GoIfT Up
InputK iDnKey
GoIfT Down
GoTo Loop
Up
Recall Status
Push
GoIfXGE 7,Loop
IncX
Push
Store Status
GoSub StatusDisplay
GoTo Loop
Down
Recall Status
Push
GoIfXLE 1,Loop
DecX
Push
Store Status
GoSub StatusDisplay
GoTo Loop
;End of test code ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
StatusDisplay:
Branch ;Test X
Target Status0 ;Goes here if X=0
Target Status1 ;Goes here if X=1
Target Status2 ;Goes here if X=2
Target Status3 ;Goes here if X=3
Target Status4 ;Goes here if X=4
Target Status5 ;Goes here if X=5
Target Status6 ;Goes here if X=6
Target Status7 ;Goes here if X=7
Status0 ;Come here to initialize the LCD. Also, display "Status: "
OBLCD_Type 2 ;initialize the LCD
OBLCD_SetCur 1,0
; ;01234567
OBLCD_Text "Status: "
;"Fall through" and add the word "Idle" at initialization time.
Status1 ;Come here to display Idle message
OBLCD_SetCur 1,8
; ;89012345
OBLCD_Text "Idle "
Return
Status2 ;Come here to display Fill message
OBLCD_SetCur 1,8
; ;89012345
OBLCD_Text "Filling "
Return
Status3 ;Come here to display Heat message
OBLCD_SetCur 1,8
; ;89012345
OBLCD_Text "Heating "
Return
Status4 ;Come here to display Wash message
OBLCD_SetCur 1,8
; ;89012345
OBLCD_Text "Washing "
Return
Status5 ;Come here to display Empty message
OBLCD_SetCur 1,8
; ;89012345
OBLCD_Text "Emptying"
Return
Status6 ;Come here to display Rinse message
OBLCD_SetCur 1,8
; ;89012345
OBLCD_Text "Rinsing "
Return
Status7 ;Come here to display Cool message
OBLCD_SetCur 1,8
; ;89012345
OBLCD_Text "Cooling "
Return