Interfacing the LCD Display to the VEX Controller
In order to build the low cost LCD display described
here, you will need to order a parallel two line by 16
character module. SparkFun or AllElectronics.com have
them for around $10-$15. The LCD module selected must
use the standard Hitachi LCD controller, otherwise it will
not work with the firmware provided in this article (go to
www.servomagazine.com).
The LCD’s parallel interface has a 14-pin connector,
but we will end up using only 10 of its pins. The LCD
construction is easy and very economical since the part list
is minimal. The VEX microcontroller does most of the work
as shown in the schematic in Figure 3.
The LCD module is connected to the microcontroller
using a four-bit parallel bus (only nine of the 16 digital
input/output pins are used). This still leaves seven digital
I/O pins, the interrupt pins, and the motor control pins
for use with other VEX devices. Some LCDs provide a
backlight that requires a separate five volt power supply,
so that increases the connector pins to 16.
The Hitachi HD44780 LCD controller is very flexible
and provides functions to position the cursor, clear the
display, and change the text attributes to blinking, bold,
backspace, scroll, or reverse video, etc. The commands
that control the Hitachi controller are shown in Table 1.
The lcd.c application that I provide with this article can
easily be modified to handle other LCD display models
such as a one line by 24 character display or a four line
by 20 character display, as long as it uses the Hitachi
controller.
Usually, you can find markings on SMT ICs on the
back of the LCD indicating the model number and
manufacturer. Some LCD displays provide pin headers,
but most just provide thru holes with .100 inch spacing.
If this is the case, then I suggest soldering .100 pin
headers to it for a convenient hookup to the
microcontroller.
When working with LCDs, I have found previous
Nuts & Volts articles written by Scott Edwards and Jon
Williams for the Parallax BS2 and BSX to be an invaluable
resource. In fact, some of the LCD code was ported from
their Parallax PBASIC examples to PIC18 C and modified
to run on the VEX controller.
These commands are sent via the four-bit parallel
bus using the WriteLCDCommand routine or WriteLCD
routine to perform various LCD related tasks, such as to
clear the LCD screen, position the cursor, or to display a
character at the current cursor position. Before using the
LCD, you need to initialize it by calling the InitializeLCD
routine. For example, if you want to clear the LCD
display and write “Hello World!!!” from your VEX
application main function, you can use the C code which
writes the LCDCLS command directly to the Hitachi LCD
controller. Be sure to include the “#include “lcd.h” file so
that the LCD functions become available; also include
lcd.c in your project.
TABLE 2. Bill of Materials for the LCD display.
ITEM
QTY DESCRIPTION SOURCE
// Setup timers, configure ports and initialize
// variables
Setup Timers();
// Initialize the LCD Display
InitializeLCD();
// Send the LCD Clear Display command to the LCD
// and have it point to
// row 1, column 1.
WriteLCDCommand(LCDCLS);
// Use the WriteLCD function to write individual
// characters starting from the
// current cursor position as follows:
WriteLCD(‘H’);
WriteLCD(‘e’);
WriteLCD(‘l’);
WriteLCD(‘l’);
WriteLCD(‘o’);
// Wait 5 second between words for pacing
pause(5000);
// You can also use my LCD version of the printf
// function to direct the text
// output to the LCD Display:
printf(“World!!!\r”);
// The ‘\r’ causes a carriage return to the next
// line on the LCD Display.
printf(“This is a test”);
LISTING 1. Some of the details regarding using the
LCD display driver which was written in PIC8 C using
MPLAB.
SERVO 06.2010 63