407
TIDE and Tibbo BASIC User Manual
©2000-2008 Tibbo Technology Inc.
on. If you are using display locking, you should ideally place locks/unlocks in each
related routine. A complication arises with regards to when to unlock the display.
For example, supposing you have two subs: lcd_sub1 and lcd_sub2:
'some main routine that invokes lcd_sub1 and lcd_sub2
....
....
lcd_sub1
...
...
lcd_sub2
...
End
Sub
'-----------------------------------------
Sub
lcd_sub1
'calls sub2 too
lcd.lock
...
lcd_sub2
...
lcd.unlock
End
Sub
'-----------------------------------------
Sub
lcd_sub2
'called by sub1
lcd.lock
...
lcd.unlock
End
Sub
Lcd_sub2 gets executed when invoked directly by the main code, and also when
the lcd_sub1 is called. In the second case, the display should not be unlocked at
the end of lcd_sub2 because the output is to be continued in lcd_sub1! And you
know what? The display won't be unlocked because with the lcd object it is
possible to nest locks/unlocks! In the following example, we do three consecutive
locks and the display is locked right on the first one. We then do three consecutive
unlocks, and the display is not unlocked until after the third one is executed:
...
lcd.lock
'lcd.lockcount=1, display is now locked
lcd.lock
'lcd.lockcount=2
lcd.lock
'lcd.lockcount=3
lcd.unlock
'lcd.lockcount=2
lcd.unlock
'lcd.lockcount=1
lcd.unlock
'lcd.lockcount=0, display is now unlocked
...
The lock/unlock mechanism maintains a counter, which can actually be read
through the
R/O property. Each invocation of lcd.lock increments
the counter by 1, each lcd.unlock decrements it by 1. The display is only unlocked
when the counter is at 0, and locked when the counter is >0. This allows you to
nest display-related procedures and safely have lock/unlock in each one of them!
424