Example: LCD backlight auto-off timers
The white LED backlight used in certain LCD displays has a lifetime of about 3000 hours at full operating current (longer at reduced currents). This is an inherent limitation of the white LED technology (2009). It is therefore advisable to turn off or dim the backlight when not in use.
This page contains several examples for either totally turning off or dimming the backlight after a certain time with no detected user activity. The light comes back on whenever a front panel button is pushed. Which of the examples you follow depends on:
- Which controller you have, MMi202, MS120 or MS12
- For the MMi202, whether it has a dimmable LCD backlight (provided via a hardware modification introduced May 2009)
- Which version of Firmware is in the controller.
- If you are using MultiTrack
Example 1: Simple on/off for MS120 and MS12 using MultiTrack
The following program code will provide a simple auto-off timer for the MS120 or MS12 backlight. It turns on the backlight whenever a front panel button is pressed, and turns it off again 10 minutes after the last button press. This is designed as a MultiTrack task. This will work in any firmware that supports MultiTrack, providing your program already uses MultiTrack. All MS120s support MultiTrack. The MS12 requires firmware V3.13 or later. For more information see reFlash: How do I determine what version firmware is in my controller?
Your program's initialisation code must contain a GoSub BKLT_Init
.
BKLT_Init: LaunchTask BKLT_Set0 Return BKLT_Set0: On 20 ;Turn On backlight MarkTime BKLT_0: YieldTask InputFM 12 ;Get the front panel buttons LoadX %11111 ;select the 5 bits representing buttons AndM GoIfT BKLT_Set0 ;G/ any button pressed LoopIfTiming 60000,BKLT_0 ;Test for timeout, loop if not yet BKLT_Set1: Off 20 ;Turn Off backlight BKLT_1: YieldTask InputFM 12 ;Get the front panel buttons LoadX %11111 ;select the 5 bits representing buttons AndM GoIfT BKLT_Set0 ;G/ any button pressed GoTo BKLT_1
Example 2: Dimmed backlight for MS120 with suitable firmware and MMi202 with suitable firmware and hardware.
If the MS120 has firmware V3.20 or later it incorporates a simple "set and forget" dimming mechanism.
If the MMi202 contains firmware V3.21 or later and it is fitted with a dimmable LCD, it supports the same "set and forget" dimming mechanism.
Your program can simply run the following code just after turn-on (i.e. in its initialization code) and the dimming will happen automatically:-
BL_HighLevel: EQU 8 ;"Bright" level, 0 to 8, 8 = 100% BL_LowLevel: EQU 1 ;"Dimmed" level, 0 to 8, 1 = 12.5% BL_DimTime: EQU 30 ;Timer value, in minutes OBLCD_Type 2 ;MUST be done before the dimmer stuff!!. Not required in MS12x SetU 0,BL_HighLevel SetU 1,BL_LowLevel SPxCmd2 1,!cpu SetU 0,BL_DimTime SPxCmd1 4,!cpu
Note that BL_HighLevel
and BL_LowLevel
must be between 0 (fully off) and 8 (fully on). Any other value will generate an error. BL_DimTime
can be 0 to 255. 0 will cause the backlight to dim immediately. 255 will give 4 hours and 15 minutes.
With this mechanism the front panel push buttons are monitored automatically (you don't have to do anything). Whenever a button is pressed it sets the backlight to BL_HightLevel
and starts the timer. Every subsequent button press restarts the timer. If the timer expires the backlight is set to BL_LowLevel
.
Example 3: Automatic detection of MS12 or MS120 and firmware version
This example lets your program automatically determine if it is running in an MS12, an MS120 with old firmware or an MS120 with newer firmware able to support backlight dimming, then initialize the display accordingly.
BL_Init: SPxPoll2 3,!CPU ;get board type pushu 1 GoIfXLT 53,BL_Old ;MS12 is type numbers 48-52 BL_ms120: SpxPoll2 0,!CPU ;Get Firmware Number pushu 0 push goifxgt 3,BL_New ;Firmware is V4.x (something later than this code!) ;There has never been a firmware lower than 3.x, so assume 3.x and test the release number x pushu 1 goifxge 20,BL_New ;3.20 and later support dimming BL_Old: initialize non-dimmable backlight goto BL_Finished BL_New: initialize dimmable backlight BL_Finished: ' ... continue ...