Summary of How to display text on 16×2 LCD using PIC18F4550 Microcontroller
This article details the process of displaying text messages on a 16x2 LCD using a PIC18F4550 microcontroller. It outlines programming steps including configuring the LCD, storing strings in character arrays, and iterating through characters to display them. The guide provides specific C code for initialization, pin definitions for control and data lines, and logic to send commands and data sequentially with delays.
Parts used in the Display Text on 16x2 LCD Project:
- PIC18F4550 Microcontroller
- 16x2 Character LCD
- High Speed (HS) Oscillator
- Port A Pins (F0, F1, F2)
- Port B Pins
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.
Code:
while(data[i]!=’\0′)
{ 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;void main(void) { TRISA=0; // Configure Port A as output port LATA=0; TRISB=0; // Configure Port B as output port LATB=0; lcd_ini(); // LCD initialization while(data[i]!='\0') { 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 rs=0; rw=0; en=1; Delay_ms(10); en=0;
For more detail: How to display text on 16×2 LCD using PIC18F4550 Microcontroller
- How is the LCD configured in the provided code?
The LCD is configured in 8-bit mode, 2 line, and 5x7 font using command 0x38. - Can the string be stored in a character array?
Yes, the article shows storing the string EngineersGarage in an unsigned char data array. - What function sends individual character values to the LCD?
The lcddata function is used to send individual character values from the string array. - Does the loop run until a null character is encountered?
Yes, the while loop continues running until the loop counter encounters the null character . - What is the purpose of the Delay_ms(300) command?
The delay is placed inside the loop to manage timing between displaying each character. - How are the LCD control pins defined in the code?
The RS, RW, and EN pins are defined as LATA.F0, LATA.F1, and LATA.F2 respectively. - What command clears the display screen?
The lcdcmd(0x01) command is used to clear the display screen. - Where does the cursor position start after initialization?
The cursor is set to the first line and first column using the lcdcmd(0x80) command.

