Академический Документы
Профессиональный Документы
Культура Документы
0 Introduction
LCD stands for Liquid Crystal Display. An LCD is a passive device. It does not produce any light and simply alters the
light travelling through it. With a voltage applied to it, the liquid crystal polarizes transmitted light in a different direction
to when no voltage is applied. A polarizing filter in front of the display then blocks one of the two polarizations (i.e. the
areas in which a voltage was applied or the ones where no voltage was applied) and therefore in some areas of the
screen appear black, this effect is used to draw the characters and graphics displayed by an LCD.
Finally, the power supply pins for the backlight LED+ and LED-. Some LCD modules come without the backlight. In
that case, these pins are not found or are left disconnected. The recommended voltage for LED+ is 4.2V and LEDshould be connected to ground (GND). Vary the value of the resistor connected to LED+ will change the brightness of
the backlight. Normally, 220 Ohm or 330 Ohm resistor will be used. For advanced user, you may connect the pin to
PWM output and change the brightness in your software by altering the PWM duty cycle. We will further discuss this in
upcoming issues.
3.0 Hardware Connection
A typical LCD hardware connection to PIC microcontroller with backlight turned on permanently is shown in figure
below. To turn off the backlight, disconnect the supplies to pin 15 and 16. RB4, RB5 and RB6 of PIC16F877A are used
for the control signals while PORTD of the microcontroller is the data bus.
interfacing with various MCUs, which operate at different speeds, or various peripheral control devices. The internal
operation of the LCD is determined by signals sent from the MCU. These signals, which include register selection
signal (RS), read/write signal (R/W), and the data bus (DB0 to DB7), make up the LCD instructions. There are four
categories of instructions:
LCD Initialization
In this part, we will see the initialization with some of the coding examples in C using Microchip MPLAB IDE and HITECH C PRO compiler for the PIC10/12/16 MCU Family. These software are free of charge and the latest releases
can be obtained from both Microchip and HI-TECH websites.
Before using the LCD for display purpose, LCD has to be initialized either by the internal reset circuit or sending set of
commands to the LCD. User has to decide whether an LCD has to be initialized by instructions or by internal reset
circuit. We will discuss both types of initialization here.
Initialization by Internal Reset Circuit
An internal reset circuit automatically initializes the HD44780U when the power is turned on. The Busy Flag (BF) is
kept in the busy state until the initialization ends (BF = 1). The busy state lasts for 10ms after VCC rises to 4.5V. The
following instructions are executed during the initialization.
Display clear
Function set:
DL = 1; 8-bit interface data
N = 0; 1-line display
F = 0; 5 x 8 dot character font
There are certain conditions that have to be met, if user wants to use initialization by internal reset circuit. These
conditions are shown in the table below.
page. Busy flag cannot be checked when you are using SK40C because the R/W (Read/Write) pin of LCD is
connected to Ground permanently. So read command is unable to be executed and delay routines must be used for
the LCD functions. The main reason to have such design is to reserve more PIC I/O pins for other applications.
It is often important to initialize the function or uses function prototypes at the beginning of the program (please refer to
source code provided here: www.robothead2toe.com.my)
Now that we are ready with the initialization routine and the busy routine for LCD, well move on to the next section on
how to send data and command to the LCD.
Sending Commands to LCD
In order to send commands we simply need to select the command register. Everything is same as we have done in
the initialization routine. But we will summarize the common steps and put them in a single subroutine. Following are
the steps:
Keeping these steps in mind we can write LCD command routine as:
Revision
General information of the LCD, circuit connection to PIC microcontroller, software initialization,
commands and instruction sets, and the basic sample program have been discussed in the previous
issues. With all that, you can display anything you want on the LCD, but it has to be based on the
predefined characters. So this tutorial is drafted to show you how to make use of the CGRAM of the LCD
to create your own characters or patterns. Hence you can display more interesting stuff on your LCD!
needed to complete each pattern. When LCD is working in 510 dots, you can only create 4 user
defined patterns. However, we will only discuss 58 dots LCD type in this article. The figure below
shows the typical 58 dots LCD pixel map for a single character.
Figure: A typical 58 dots character pixel
map showing L.
CGRAM Address
The memory map of the 8 user defined
characters is given in the table below. The
first character will occupy 8 bytes, starting
from 000, until 007. Then the next
character starts at 008 and ended at 0x0F. This trend continues until the end of the CGRAM address,
which
is
0x3F.
Pattern
0
1
2
3
4
5
6
7
Pattern
0
1
2
3
4
5
6
7
Fixed
DB7
DB6
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
Hexadecimal Code
DB0
0
0
0
0
0
0
0
0
040
048
050
058
060
068
070
078
hexadecimal value for each row of pixels, but the simplest way is to look into the binary value.
All we have to do is make a pixel-map of 58 and get the binary value for each row. A bit value is 1 if
the pixel is glowing and the bit value is 0 if that pixel is off. Ill use a smiley J pattern to further explain
it. The figure shows my version of smiley face. It may look less smooth due to the limited pixels
available but I believe you can recognize the happy face with a pair of eyes and the raised mouths
corners.
Figure: Smiley pattern with the corresponding binary value for each row.
The last row is usually left blank (0b00000000) for the cursor. If you are not using cursor, you can also
make use of that row 7. This will give you more pixels for one pattern. Now we have the values for each
row to create a smiley pattern. As you can see in the table below, the binary value can be used directly
as the argument for LCD_senddata( ) function. We only need to add 0b in front of each value to
declare
that
it
is
a
binary
value.
Row
0
1
2
3
4
5
6
7
Argument x in lcd_senddata(x)
0b00000000
0b00001010
0b00001010
0b00000000
0b00010001
0b00001110
0b00000000
0b00000000
C Programming
Lets say if we want to write the smiley pattern at pattern location 1. So we send the command as 048
(= 040 + 008), and then we send the pattern data. The details description LCD_command( ) and
LCD_senddata( ) subroutines is mentioned in LCD Interfacing with PIC Microcontrollers (Part 2). Below
is
the
C
code
to
do
this.
Bottom of Form
Figure: C code to display the user defined character, pattern 1.
More examples of custom characters are shown in the figure below. As you can see, we can even
combine
two
standard
characters
into
one
58
dots
frame
too.
Conclusion
The tutorial on custom character ends here. Hope you enjoy creating your own custom characters. We
will continue our discussion on LCD backlight power saving method in the next issue.