Guides‎ > ‎

2x16 Character LCD with C18

posted Nov 24, 2010, 6:18 PM by Danny Ng   [ updated Feb 8, 2011, 6:40 PM ]
The gadget you added is not valid

The 2x16 character LCD based on the HD44780 controller are a commonly used for Display purposes on micro controller project. There is a simple way to include the use of LCD in a project when developing with C18. A utility call Application Maestro is provided together with the installation of MPLAB allow the generation of library for LCD. The pin configuration for the port used for Data, RW, RS and EN pin, interface methods (4bit or 8bit) can be selected. Beside that there is 2 mode that can be selected for driving the LCD.

The 1st mode is Blocking which uses delay for displaying of character. In this mode, the RW pin of the LCD is grounded. After passing the required data for display to the LCD, a delay that is longer than the maximum busy period is called. This will ensure that the next command or data is received during the non busy duration.
The 2nd mode uses Busy flag check. During internal processing the the BF(data7) pin of the LCD will be high. Checking on this pin will make sure that the next command will be written at the correct time. The 1st method uses 1 IO port less then the 2nd but losses the function to read data from the LCD. For the example I will use the Busy flag method to drive the LCD. The settings are set as the picture shown above and the code for the LCD is generated.

The code are tried out on PIC18F2455. It is connected according to schematic above.  There will be a 5 files generated from application maestro. xlcd.def, xlcd.h and xlcd.c must be included into the project for compilation. There is a PDF and example file generated also to show the usage of all the function in xlcd.h. By using the code below and adding include the generated files the LCD will display the text in the code. 4 delay functions (XLCDDelay15ms, XLCDDelay4ms, XLCD_Delay500ns and XLCDDelay) have to created by the user for the LCD routine to work properly. The attached PDF file is the similar file generated by application maestro contains details of all the function that can be used with the library.

#include <p18f2455.h>
#include <delays.h>
#include "xlcd.h"

#pragma config FOSC = INTOSCIO_EC
#pragma config WDT = OFF
#pragma config MCLRE = OFF
#pragma config PWRT = ON
#pragma config LVP = OFF

void XLCDDelay15ms (void)
void XLCDDelay4ms (void)
void XLCD_Delay500ns(void)
void XLCDDelay(void){ //1.5ms delay

void main(void){
char data[]="LCD Test";
OSCCON = 0x70;
With everything connected up the output in the 1st figure can be obtained.

Danny Ng,
Nov 24, 2010, 6:21 PM
Danny Ng,
Nov 24, 2010, 6:21 PM