Projects   /   LCD & Display Projects   /   PIC18F4550

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 16x2 character LCD.

Published

At a glance

CategoryLCD & Display Projects
PIC modelPIC18F4550
IncludesCircuit diagram · Video
Reading time~3 min
Jump to a section
  1. Project Source Code
  2. Circuit Diagrams
  3. Project Components
  4. Project Video
  5. Quick Solutions to Questions related to Display Text on 16x2 LCD Project:
  6. Related projects

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 involving LCD configuration, string storage in a character array, and iterative character transmission via the `lcddata()` function within a loop. The provided C code initializes ports, sets up the LCD in 8-bit mode, and displays the string "EngineersGarage" with a delay between characters.

Parts used in the Display Text on 16x2 LCD Project:

  • LCD
  • PIC18F4550 Microcontroller
  • Preset
Programming 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 ‘’ of the string.
·         Use lcddata() function to send individual character values of the string to be displayed on LCD. 

Code:

while(data[i]!=’’)
    {
        lcddata(data[i]);   
        i++;
        Delay_ms(300);
    }

Project Source Code

###


// 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]!='')
{
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;
}

void lcddata(unsigned char dataout)
{
lcdport=dataout; //Send data to lcdport=PORTB
rs=1;
rw=0;
en=1;
Delay_ms(10);
en=0;
}

###

Circuit Diagrams

Circuit Diagrams 3

Project Components

Project Video

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

  • How is the string stored for display?
    A string is stored in a character array named data.
  • What function sends individual characters to the LCD?
    The lcddata() function is used to send individual character values.
  • How does the program know when to stop displaying characters?
    The loop runs until the loop counter encounters the null character of the string.
  • Which oscillator is selected in the configuration bits?
    The High Speed (HS) oscillator is selected.
  • What is the delay time set between displaying characters?
    A delay of 300 milliseconds is used between each character.
  • How are Port A and Port B configured?
    Both Port A and Port B are configured as output ports.
  • What command configures the LCD in 8-bit mode?
    The command 0x38 configures the LCD in 8-bit mode, 2 line, and 5x7 font.
  • Where does the cursor start after initialization?
    The cursor position is set to the 1st line and 1st column.
Beginner Tutorials · PIC18F4550

PICDEM FS USB CDC Evaluation Board using PIC18F4550 with Proteus Simulation

Introduction The PICDEM FS USB CDC Evaluation Board is a practical microcontroller project built around the PIC18F4550, designed to demonstrate USB communication...

Peripheral Tutorials · PIC18F4550

PICDEM FS USB Mass Storage Device using PIC18F4550 with Proteus Simulation

Introduction This microcontroller project demonstrates how to simulate a USB Mass Storage Device (MSD) using the PIC18F4550 in a Proteus simulation environment....

Development Boards & Kits · PIC18F2550

Pinguino Project: A PIC Microcontroller Based Arduino

This is a complete tutorial to make a PIC Microcontroller based Arduino. This is a complete tutorial to make PIC microcontroller based...

LCD & Display Projects

Leveraging Blockout Banners for Effective Electronics and Tech Product Displays

Blockout banners have become a popular and effective tool for displaying electronics and tech products in various settings, from trade shows and...

LCD & Display Projects · PIC18F4520

Interfacing PIC18F4520 microcontroller with an HD44780 LCD

Introduction Being able to display data from a microcontroller visually has many advantages. It allows for menus, status indicators, and instructions to...

LCD & Display Projects

Video Project Development in the Midst of an Impromptu Online Semester

Receiving robot parts in the mail was an unexpected conclusion to the Winter 2020 semester for students. However, when faced with a...

Muhammad Bilal

Muhammad Bilal

I am a highly skilled and motivated individual with a Master's degree in Computer Science. I have extensive experience in technical writing and a deep understanding of SEO practices.