Projects   /   LCD & Display Projects   /   PIC16F877A

Serial LCD project using PIC16F877A Microcontroller

This project shows you how to create a serial LCD module that you can drive from any serial RS232 interface.

Published

At a glance

CategoryLCD & Display Projects
PIC modelPIC16F877A
Reading time~4 min
Jump to a section
  1. Serial LCD Command set
  2. X and Y commands
  3. Quick Solutions to Questions related to Serial LCD Project:
  4. Related projects

Summary of Serial LCD project using PIC16F877A Microcontroller

This article describes a serial LCD module project driven by an RS232 interface using a simple ASCII command set. It supports manual testing via terminal programs and can be integrated with microcontrollers like the PIC16F877A for debugging or custom applications. The system operates at 2400 baud with a 20MHz crystal, allowing users to control cursor position, display modes, and scrolling through easy-to-type commands prefixed with '#'.

Parts used in the Serial LCD Project:

  • Serial LCD Module
  • RS232 Interface
  • Terminal Program (e.g., Hyperterminal)
  • MikroC Compiler
  • PIC16F877A Microcontroller
  • 20Mhz Crystal
  • Level Translator (optional for 0-5V input)

This project shows you how to create a serial LCD module that you can drive from any serial RS232 interface. It uses a pure ASCII command set so you can control it easily from a terminal program such as Hyperterminal.
There  are no 'odd' command sequences such as 0xef to define a command  - you can type all commands at the terminal interface making it very easy to use

Serial LCD project
It's also easy to test it out manually before driving it with a program.

Once you have decided what you want to do a microcontroller can generate the same commands or you can send them from a PC program.

If you want to use it as a debugging terminal for your PIC projects then it makes sense to remove the level translator and just use the  0-5V input otherwise you would end up having two level translators for no real reason!

Note: Using it like this you will need to invert the RS232 output data so you either need an inverter chip if driven from the built in USART or you can drive it using a software USART (The transmitter part anyway) since you will have full control over the output signal.

Serial LCD Specification

 

Baud Rate 2400
Crystal 20Mhz - you can use  a lower value xtal but must re-compile the files and set the clock value into the MikroC chip settings.

Serial LCD Project Details

You can recompile the serial LCD files if you want examine code operation (using the built in simulator) or change the source code. Note the hex file is contained in the download.

 

Serial LCD Command set

All commands are prefixed with the hash character '#'.  In all cases except #X and #Y the single character following the '#' causes a command to execute.  For #X and #Y the decimal digits following (up to 2 digits) specify a position on the display.

Note: for #X and #Y the top left position is at 0,0.

Serial LCD Command Set list (uses upper or lower case):

 

Serial LCD Commands
#C or #c Clear screen
#H or #h Cursor Home
#L or #l Cursor Left
#R or #r Cursor Right
#U or #u Cursor Underline mode
#B or #b Cursor Block mode
#I or #i Cursor Invisible
#F or #f Display OFf 
#O or #o Display On
#Xnn or #xnn Cursor X position (left nn=0)
#Ynn or #ynn Cursor Y position (top nn=0)
#> or #. Scroll display right (hash dot as easier to type!)
#< or #, Scroll display left (hash comma as easier to type!)
## Display a '#' character.

 

To clear the display you would type:

#C

To set the cursor to block mode type:

#B

X and Y commands

There must be at least two digits following the  #X or #Y command unless the following command is not a digit.   All this means is that you can finish an X or Y commands by typing a letter - if you type a digit the parser won't know if it is a digit to display or a digit to specify the position.

Here is a cursor positioning example command sequence:

#H Home Sets cursor position to (0,0) - top left.
#X3JFM Set X and print Sets the X position to 3 and prints JFM
(Note the cursor is only moved once the J is entered).

You can also use the longer command:

#H#X00JFM

It does exactly the same thing but the cursor is immediately moved after the '00' since the command parser knows that it is the end of the X cursor position command as it only accepts 2 digits.

 

For more detail: Serial LCD project using PIC16F877A Microcontroller

  • How do I clear the screen?
    Type the command #C.
  • Can I use a lower value crystal than 20Mhz?
    Yes, but you must recompile the files and set the clock value into the MikroC chip settings.
  • What character prefixes all commands?
    All commands are prefixed with the hash character #.
  • How do I move the cursor to a specific X position?
    Use the #X command followed by two decimal digits representing the column number.
  • What happens if I type a digit after #X without two digits?
    The parser may not know if it is a digit to display or part of the position specification unless followed by a non-digit.
  • How can I scroll the display right?
    Type #> or #. to scroll the display right.
  • Do I need a level translator for 0-5V inputs?
    No, you should remove the level translator if driving directly from 0-5V inputs to avoid redundancy.
  • How do I handle RS232 output data inversion?
    You need an inverter chip if driven from the built-in USART or use a software USART for full control.
Beginner Tutorials · PIC16F877A

PIC16F877 Driving LCD in 4-Bit Mode using PIC16F877 with Proteus Simulation

Introduction This microcontroller project shows how a PIC16F877 can drive an LCD display using 4-bit mode inside a Proteus simulation.The project demonstrates...

Programmers & ICSP · PIC16F877A

EPE PIC/LCD Demo using PIC16F877 with Proteus Simulation

IntroductionThe EPE PIC/LCD Demo is a classic microcontroller project that demonstrates how a PIC16F877 can fully control a PG12864F graphical LCD.Designed as...

Motors & Robotics · PIC16F877A

Efficient Sun-Following Robot: A Solar Tracker with Microcontroller Control

Abstract The impending global challenge of dwindling non-renewable fuel resources underscores the urgency of transitioning towards renewable energy alternatives like solar power....

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...

Ibrar Ayyub

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...