External LCD Library

External LCD: (Page#79)

The External LCD library can be used to work with an HD44780 LCD controller in both nibble as well as byte mode. The assignments for different LCD pins and the specification of the mode in which it is to be used is specified in the xlcd.h present in the h subfolder of the compiler installation. There are 3 delay functions that one needs to create too 18 clock cycles, 5ms and 15 ms for the lcd functions to work. Also, the operation that one performs such as writing to data ram, sending command’s etc requires that its corresponding source file be added from src\pmc_common\XLCD in the compiler directory. Following are the functions present in this library:

OpenXLCD(arguments):

The OpenXLCD function is used to configure the PIC input output pins and also to initialize the LCD controller.

BusyXLCD():

This function returns the status of the busy flag of the LCD controller.

SetDDRamAddr(arguments):

This function is used to set the data display address of the RAM.

WriteCmdXLCD(arguments):

This function is used to write a command to the LCD controller.

SetDDRamAddr(arguments):

This function is used to set the data display address.

putcXLCD(arguments)/ WriteDataXLCD(arguments):

These functions write a byte of data to the LCD controller.

putsXLCD(arguments)/ putrsXLCD(arguments):

These functions write a string to the LCD controller. The putrsXLCD function is used when the string is defined in rom.

SetCGRamAddr(arguments):

This function is used to the address of the character generator.

ReadAddrXLCD():

This function reads an address byte from the LCD controller. Whether the read address is of the Data Display RAM or the Character Generator RAM is determined by the last set?Ramaddr function.

ReadDataXLCD():

This function reads a data byte from the LCD controller. Whether the read data is of the Data Display RAM or the Character Generator RAM is determined by the last set?Ramaddr function.

Here is the code(requires additional files to be added in the project, download the whole folder from the link):

Code

//This is a program that demonstrates the use of software LCD control with

//Microchips Libraries.It simply displays "Hello World!"

//The External LCD Section is documented on P#79 of C18 Libraries

//Use 181320LCD_CAPTURE.DSN

//Replace this xlcd.h in the MCC18>h folder.

//Add all files in the folder in your projec.Also present in MCC18 isntallation folder.

//Pin changes have been made in the provided xlcd.h file.

#include<p18f1320.h>// Include files and definitions for the Processor

#include<xlcd.h>// Include function definitions for the External LCD Library library

#include<delays.h>// Include function definitions for built in Delay routines

#pragma config LVP=OFF,OSC=INTIO2,WDT=OFF// Use internal Oscillator, Watchdog off, LVP off

void main(void)

{

unsigned char data[]="Hello World!";

OSCCON=0x60;//Internal 4MHZ Oscillator

ADCON1=0X7F;//Make all ports Digital

OpenXLCD( EIGHT_BIT & LINES_5X7 );// Use 8 bit Data, 5x7 pixel Matrix per character

while( BusyXLCD());// Wait till LCD finishes executing command

WriteCmdXLCD( CURSOR_ON);// Turn cursor ON

while( BusyXLCD() );// Wait till LCD finishes executing command

WriteCmdXLCD( SHIFT_DISP_LEFT );//Shift Cursor Display Left

while( BusyXLCD());// Wait till LCD finishes executing command

putsXLCD(data);// Write the String data to the LCD

while(1);// Wait here

}

// As indicated in the C18 libraries manual

// These delays are required for LCD operation

/****************************************************************/

// DelayFor18TCY =18 cycles.

/****************************************************************/

void DelayFor18TCY(void)

{

_asm NOP _endasm

_asm NOP _endasm

_asm NOP _endasm

_asm NOP _endasm

_asm NOP _endasm

_asm NOP _endasm

_asm NOP _endasm

_asm NOP _endasm

_asm NOP _endasm

_asm NOP _endasm

_asm NOP _endasm

_asm NOP _endasm

_asm NOP _endasm

_asm NOP _endasm

_asm NOP _endasm

_asm NOP _endasm

_asm NOP _endasm

_asm NOP _endasm

}

/****************************************************************/

// DelayPORXLCD =15 ms.

/****************************************************************/

void DelayPORXLCD(void)

{

Delay1KTCYx(15);

}

/****************************************************************/

// DelayXLCD =5 ms.

/****************************************************************/

void DelayXLCD(void)

{

Delay1KTCYx(5);

}

The code for the External LCD functions and the additional files required to run it can be downloaded from:

http://www.box.net/shared/ygm6ml3ou2