Backlight Control

Let’s control the LCD backlight of the 20×4 LCD.

Schematic Diagram: A simplified circuit of the backlight control driven by a PNP transistor 9015 and controlled by MCU port P2.3  (port 2 bit 3), such that :

  • P2.3 = Logic low = backlight On
  • P2.3 = Logic High = backlight Off

 

Program Instruction: You can write the following program as:

P2.3 = 0     'backlight ON

P2.3 = 1     'backlight OFF

To blink the backlight,

'******************************************************************
'Lerning 8051 core MCU
'by F. Dandy
'1diyshare.com
'******************************************************************

' Program Name : BAcklight Control of 20x4 LCD Module

'Declaration

LCD_Backlight Alias P2.3      ' rename P2.3 into a meaningful understandable port
                              ' as the port to control the backlight

Do

   LCD_Backlight = 0            ' command LCD_Backlight port to logic 0
                                ' this will make the backlight to turn ON
   Waitms 50                    ' put a delay so we can see it is lighted

   LCD_Backlight = 1            ' command LCD_Backlight port to logic 1
                                ' this will make the backlight to turned-off

   Waitms 50                    ' put a delay so we can see it is turned off

Loop                            ' repeat from the start with DO

End                             ' end of the program

 

Next :  Let’s display a letter on the LCD