LCD: Interfacing with PIC Microcontrollers (Part 4)

By SC Lim, RH2T Vol.7, Jan11

Power saving, a famous term in modem electronics world, yet one of the elements that ensure your products stand out from the crowd. Hence this tutorial will explore the method to reduce the power consumption of the LCD and flexibly adjust the backlight brightness at the same time.

 1.0 Introduction to LCD Backlight

LCD’s characters are visible with the presence of ambient light but are hardly seen in the dark. In order to improve the visibility, backlighting is added to the LCD display.

Figure: Various LCDs with different backlight colors.

Light Emitting Diode, or LED, backlight is the most popular backlighting for small and medium LCDs. The advantages of LED backlighting are its low cost, long life, immunity to vibration, low operational voltage, and precise control over its intensity. The main drawback is it does require more power than most of the other methods such as Electroluminescence Panel (ELP) Backlighting and this is a major drawback if the LCD size is large.

LED backlights come in a variety of colors, with yellow-green being the most common, red, blue, and now white is becoming cost effective and very popular. LED backlights offer a longer operating life – 50,000 hours minimum and are brighter than ELPs. Being a solid state device, they are configured to operate with typically a +5VDC power (and optionally 12VDC power), so they do not require an inverter. The LED backlight has two basic configurations; Array and edge lit. In both types the LEDs are the light sources that are focused into a diffuser that distributes the light evenly behind the viewing area.

Figure: Array lit LED lightbox

Figure: Edge lit LED lightbox

In Array lit configuration there are many LEDs mounted uniformly behind the display, it offers more uniform and brighter lighting and consumes more power. In Edge lit configuration, the LEDs are mounted to one side and focused into the diffuser, it offers a thinner package and consumes less power.

2.0 Conventional LCD Backlight Control Method

If you still can remember, figure below is the schematic I showed in Part 1 of the LCD tutorials. A current limiting resistor at the value of 220ohm was connected between +5VDC and LED+ pin, while LED- pin was connected to GND (0V). To adjust the brightness of the LCD backlight, we can change the value of the resistor. A smaller resistor value yields brighter backlight and a greater resistor value produces dimmer effect. This simple approach is perfectly acceptable for most applications.

Figure: Schematic with fixed backlight brightness

May be you’ll think of a brilliant idea to replace the fixed value resistor with a variable resistor or a preset. Then you may alter the backlight brightness by adjusting the variable resistor manually whenever you wish. However, this method is not suitable to be used when you want to adjust the backlight brightness automatically. For example, when you have an ambient light sensor to measure the luminance of your room and automatically control the backlight brightness to ensure the visibility of the text displayed on the LCD, this method cannot be applied.

3.0 Driving LCD Backlight using PWM

The improved method would be controlling backlight brightness using Pulse Width Modulation (PWM). A NPN general purpose transistor, 2N2222, is used as a switch to turn the backlight on and off rapidly. 2N2222’s continuous collector current, IC, is rated at 1A. It is more than enough to drive the backlight which normally consumes around 120mA.

Figure: Improved schematic with PWM backlight control

Logic 1 at the transistor base (B) will turn the transistor on while logic 0 switches the transistor off. When the transistor is turned on, current flows through the LED backlight from +5V power supply. The current continues to flow through the transistor and finally to the ground. Since the loop is completed, it turns on the backlight. When the transistor is switched off, the loop cannot be completed (opened). No current flow through either the transistor or LED backlight. Hence the backlight is turned off.

Let’s consider a LED backlight module where the nominal LED driving current for this display is 120mA which produces a typical brightness of 50NIT (The SI unit for luminance is candela per square meter (cd/m2). A non-SI term for the same unit is the “NIT”. Hence 1cd/m2 = 1NIT). If, instead of a DC or constant current, we apply 5 times the current, 600mA, for 1/5 of the time, the average current is the same, 120mA.

Figure: Pulsed current versus average current

The average brightness of the LED would also be the same if measured electronically. The difference is in the brightness perceived. The human eye has a certain amount of persistence. If exposed to a bright light the eye will “remember” the light for a short period of time. This allows us to view a motion picture or TV screen as a steady image when in fact it is flickering at 24 to 30 times a second. So when the LED is flashed on brightly for a short time and then turned off, our eyes “remember” the light at the high brightness level. The result is that the perceived brightness of the back light is closer to the high pulsed brightness than to the lower average DC brightness. Therefore we see a brighter backlight although the power consumed is the same.

This effect can be used to advantage in several ways. If the brightest possible backlight is needed, the display can be pulsed at 1:4 on/off ratio with 5 times the typical current. The pulse repetition frequency should be greater than 100Hz so the flickering is not perceptible to the eye.

This technique can also be used to give a “normal” brightness level to the display but at a lower average current to save power. The average power can be cut by a factor of at least 30% to produce a given perceived brightness level. This can be a big advantage in battery operated equipment. You will sense the different once you try it out.

If we change the LED type backlight brightness by simply varying the DC current with different resistance in series to the power supply, the individual LED emitters start to become visible at low current, resulting in an uneven looking back light. So the third use of the PWM method is to facilitate a wide range of brightness control for the LED backlight, without an uneven looking backlight. By varying the on/off ratio of the controlling PWM waveform, a very wide range of brightness can be achieved while maintaining a very even appearing backlight.

4.0 Programming

After we have connected the circuit as shown in section 3.0, we need to write the program to be loaded to the PIC microcontroller in order to generate the PWM to drive the transistor. Since we’re controlling the backlight using PWM method, we need to configure the CCP1 module in our PIC microcontroller. Besides, we have to setup Timer2 module too because it is used as the PWM time base.

I’ve touched up the program of the previous tutorials and added several new routines for this tutorial. The following instructions are given in PIC16F877A’s datasheet in order to setup PWM operation.

1. Set the PWM period by writing to the PR2 register.

2. Set the PWM duty cycle by writing to the CCPR1L register and CCP1CON<5:4> bits.

3. Make the CCP1 pin an output by clearing the TRISC<2> bit.

4. Set the TMR2 prescale value and enable Timer2 by writing to T2CON.

5. Configure the CCP1 module for PWM operation.

By following the steps, the configuration is shown below.

Figure: Setup for PWM operation.

The following routine put the desired PWM value into CCP1L register. We neglected the two least significant bits of the duty cycle register at CCP1CON<5:4>. This will create a much simpler routine, but reduced the resolution of the PWM duty cycle from 10 bits to 8 bits. However, 8 bits resolution is already sufficient for our application, which means it accepts value from 0 to 255.

Figure: Routine to set the backlight brightness.

Now we can set the desired backlight brightness in our main routine by using the function above. For example:

Figure: Different backlight brightness through PWM control.

As you can see the backlight brightness changes proportional to PWM duty cycle. The greater the duty cycle, the brighter it is. This is because the average brightness illuminated from the backlight panel is increased with the amount of time the backlight is turned on. This turn on time is the PWM duty cycle.


Since we talked about the power saving in the beginning of this tutorial, I’ve tried to measure the current consumption of my basic circuit comprises of a PIC16F877A, LM7805 voltage regulator, two 3mm LEDs, a few 10K pull up resister, 20MHz crystal and some essential components like capacitors and resisters. Only Timer2 and CCP1 modules were running in the program. The multimeter measures 97.7mA current when the backlight is turned off (PWM duty cycle = 0) and 140.5mA current when the backlight is fully ‘ON’ (PWM duty cycle = 255). So there is as much as 42.8mA current being consumed when the backlight is fully ‘ON’. This little amount counts when it comes to battery operated system. The more we saved, the longer the system runs.

Okay, that’s all for this issue. You may visit , vol.7 to download the complete source code. RH2T


1. Hitachi HD66710 Datasheet



4. Others reference:

2 thoughts on “LCD: Interfacing with PIC Microcontrollers (Part 4)”

  1. Hi, im doing a final year project on Cuk converter using PIC16F877A with LCD and my main objective is to control the current consumption. I was wondering is it possible to adjusting the lcd brightness without increasing the current? If so can you help me with the program. secondly, how can i display the negative output at the lcd?
    Much thanks.


Leave a Comment

Your email address will not be published.

Share this Tutorial

Share on facebook
Share on whatsapp
Share on email
Share on print
Share on twitter
Share on pinterest
Share on facebook
Share on whatsapp
Share on email
Share on print
Share on twitter
Share on pinterest

Latest Tutorial

BLTouch Installation for Ender 3 with 32-bit V4.2.2 Board
Pick and Send Random Meal’s Option and Locations through Telegram Bot Using Grove WiFi 8266 on micro:bit
DIY Automated Vacuum Cleaner Using REKA:BIT With Micro:bit
Rainbow Spark in Mini House using Maker Uno.
TinyML on Arduino using Edge Impulse
Tutorials of Cytron Technologies Scroll to Top