Hi bengchet,
Here is the C18 code:. Using C18 built-in libraries
#include <P18F4550.h>
#include<xlcd.h> //built-in LCD library
#include<delays.h>
#pragma config FOSC = XT_XT, PWRT = ON, MCLRE = ON
#pragma config WDT = OFF, PBADEN = OFF, LVP = OFF
//The built library for using LCD requires that we provide 3 types of
//delays - 15mS, 18Cycles, 5mS.
void DelayPORXLCD(void) //15mS delay
{
Delay1KTCYx(15);
}
void DelayFor18TCY(void) //18 cycle delay
{
Nop(); Nop(); Nop(); Nop();
Nop(); Nop(); Nop(); Nop();
Nop(); Nop(); Nop(); Nop();
Nop(); Nop(); Nop(); Nop();
Nop(); Nop();
}
void DelayXLCD(void) //5mS delay
{
Delay1KTCYx(5);
}
void main(void)
{
ADCON1=0x0F; //PORTB digital
TRISD=0; //outputs
TRISB=0;
OpenXLCD(EIGHT_BIT & LINES_5X7); //LCD set-up
while(BusyXLCD( ));
WriteCmdXLCD(0x0C); //on display, off cursor
while(BusyXLCD( ));
SetDDRamAddr(0x82); //character start position
while(BusyXLCD( ));
WriteCmdXLCD(SHIFT_DISP_LEFT); //cursor moves right
//for each character
putrsXLCD("Hello World!"); //string placed in ROM
while(1);
}
Here is the Project Set up;
- Project Set up.JPG (23.48 KiB) Viewed 7344 times
Here are the changes made to xlcd.h library #define BIT8
/* When in 4-bit interface define if the data is in the upper
* or lower nibble. For lower nibble, comment the #define UPPER
*/
/* #define UPPER */
/* DATA_PORT defines the port to which the LCD data lines are connected */
#define DATA_PORT PORTD
#define TRIS_DATA_PORT TRISD
/* CTRL_PORT defines the port where the control lines are connected.
* These are just samples, change to match your application.
*/
#define RW_PIN LATBbits.LATB3 /* PORT for RW */
#define TRIS_RW TRISBbits.TRISB3 /* TRIS for RW */
#define RS_PIN LATBbits.LATB4 /* PORT for RS */
#define TRIS_RS TRISBbits.TRISB4 /* TRIS for RS */
#define E_PIN LATBbits.LATB5 /* PORT for E */
#define TRIS_E TRISBbits.TRISB5 /* TRIS for E */
Thanks for your help.