How to display text on 16×2 LCD using PIC18F4550 Microcontroller

Several automated and semi-automated devices require a message to be displayed in order to indicate their working status. In continuation to LCD interfacing with PIC18F4550, this article explains how to display a message or string on a 16×2 character LCD.

How to display text on 16x2 LCD using PIC18F4550 MicrocontrollerProgramming steps:

·         Configure the LCD.
·         Store a string in a character array.
unsigned char data[20]=“EngineersGarage”;
·         Run a loop till the loop counter encounters the null character ‘\0’ of the string.
·         Use lcddata() function to send individual character values of the string to be displayed on LCD.


{        lcddata(data[i]);
i++;        Delay_ms(300);    }

// Program to display text on 16x2 LCD using PIC18F4550 Microcontroller

// Configuration bits
/* _CPUDIV_OSC1_PLL2_1L,  // Divide clock by 2
   _FOSC_HS_1H,           // Select High Speed (HS) oscillator
   _WDT_OFF_2H,           // Watchdog Timer off
   MCLRE_ON_3H            // Master Clear on

//LCD Control pins
#define rs LATA.F0
#define rw LATA.F1
#define en LATA.F2

//LCD Data pins
#define lcdport LATB

void lcd_ini();
void lcdcmd(unsigned char);
void lcddata(unsigned char);
unsigned char data[20]="EngineersGarage";
unsigned int i=0;
How to display text on 16x2 LCD using PIC18F4550 Microcontrollervoid main(void)
	TRISA=0;		// Configure Port A as output port
	TRISB=0;		// Configure Port B as output port
	lcd_ini();		// LCD initialization
	{		lcddata(data[i]);	// Call lcddata function to send characters
					// one by one from "data" array
		i++;		Delay_ms(300);
	}}void lcd_ini()
{	lcdcmd(0x38);		// Configure the LCD in 8-bit mode, 2 line and 5x7 font
	lcdcmd(0x0C);		// Display On and Cursor Off
	lcdcmd(0x01);		// Clear display screen
	lcdcmd(0x06);		// Increment cursor
	lcdcmd(0x80);		// Set cursor position to 1st line, 1st column}

void lcdcmd(unsigned char cmdout)
{	lcdport=cmdout;		//Send command to lcdport=PORTB


For more detail: How to display text on 16×2 LCD using PIC18F4550 Microcontroller

About The Author

Ibrar Ayyub

I am an experienced technical writer holding a Master's degree in computer science from BZU Multan, Pakistan University. With a background spanning various industries, particularly in home automation and engineering, I have honed my skills in crafting clear and concise content. Proficient in leveraging infographics and diagrams, I strive to simplify complex concepts for readers. My strength lies in thorough research and presenting information in a structured and logical format.

Follow Us:

Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.