Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Auto-off for LCD backlight

Status
Not open for further replies.

SanjayPhirke

New Member
In my 89S52 design, I want to make the LCD back-light on for specified period as soon as any key is pressed. After that duration the back-light goes off provided no switch is pressed again during that period.

I get a low signal for any switch pressed. So I can use an external interrupt along with a timer. But for this simple work two interrupt resources will be occupied.

Can somebody suggest me a simpler method. Is it possible by using timer2 alone(T2EX pin)? In Capture mode, interrupt is generated on high-to-low transition at T2EX. At the same time it can also be used as regular timer...
 
If you are not doing much serious in your main program, you can use polling method for sensing switches, and once a switch is pressed, start a timer. When the timer expires, you can turn OFF the backlight.
In between if any keypress is sensed again reload the time value.
Hope this helps.
 
Thanks srikanthsamaga,

I thought on it, & found that it is not at all necessary to use interrupt for switch detection. I will just poll & use a timer for duration.
 
In simple control systems like this it's always useful to have a timer interrupt running at say 100ms intervals all the time.
You have a variable that can increment once triggered. My example is in pseudo code and can easily be adapted to use multiple timers within a single interrupt.
My example uses polling under interrupt to start timers. Very simple. Why waste an interrupt on something like a key press than can be active for millions of clock cycles.
init
{
lightimer=0
light=off
}

Interrupt every 100ms
{
if switchedpressed=yes
{
light=on
lightimer=1 // kicks off the state machine
}
If lighttimer isnt equal to 0 then lighttimer++ // increments timer as the count process has been started by pressing the switch
if lighttimer=100 // it's reached 10 (100 counts at 100ms equals 10secs) seconds so
{
light=off
lighttimer=0 //reset the timer and lock the state machine off until the switch is pressed again
}
}

This example starts a 10 second countdown from the moment the light switch or event expires like the switch has been released. It can also be used to light the display if an event occurs that may need you see it on the backlit display by simply setting the lightimer variable to 1 when this event occurs without anything having been pressed i.e. low battery.
 
Last edited:
Really good, thanks!!!

:eek: Thanks, it is really very good technique. I had done polling in the main loop. But your method is excellent because it will works even if main loop is busy & an event happened which needs to glow backlight.

Secondly as the timer interrupt is already used for switching off the light, it can always be used to check the switches (& any other) status. Thank you again, I will replace my code with this one.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top