Character lcd 16x2Character lcd 16x2

Character LCD is very common and basic accessory, required in most of Embedded system projects.  In today’s post we are making LCD Driver library(Compact Version) for our daily life project usage. Most of the code is inspired and borrowed from Flex-LCD Driver Library. In this driver we will only specific features which are required in our day to day projects and we will avoid features which are rarely used. Because saving IO pins is essential Task in Embedded systems, so we will only focus on 4bit mode instead of 8bit. Also we will not use R/W pin and will pull this pin to ground. 

Hardware Requirements

Functions List

We are going to implement following functions with specified features and usage 

PIN DEFINITIONS Before using library we need to define interfacing pins so that we could use them later. We had defined pins as following

#define LCD_DB4   PIN_B4

#define LCD_DB5   PIN_B5

#define LCD_DB6   PIN_B6

#define LCD_DB7   PIN_B7

#define LCD_E     PIN_B3

#define LCD_RS   PIN_B2

These pins are for the Microchip PicDem2-Plus board,Change these
pins to fit your own board

lcd_init(); Required to call once before using any of library function. This will send initialization commands to Character LCD and force it to operate in 4 bit mode without the usage of R/W pin.

void lcd_gotoxy(int8 x, int8 y)  This function will place cursor to specified x,y position. Here x represents column number in LCD and y represents Row number. Maximum 4 rows are supported and column could be 10, 16 or 20 according to LCD type you are using. Also remember that x starts from 0 and y starts from 1. 

void lcd_putc(char c) This function will print characters to LCD from current cursor position. 

void lcd_cursor_on(int1 on)  Sending True will turn Cursor ON and sending False will turn Cursor OFF. 

Example Code and Usage

Here we are providing example code and link to the GitHub repository where you can find this and many more PIC codes to use in your projects. In this example usage we are printing Simple welcome message again and again after some delay

LCD Driver in 4bit mode usage example
Program Output in Proteus

   Example Usage of LCD4Bit Character Library Driver Usage
   @Author: Abdul Rehman
   @Note: Use this on your own. Author is not responsible for anything


#include <16F887.h>
#device *= 16 
#use delay(clock=8000000)
#use I2C(Master, SDA = pin_C4, SCL = pin_C3) 
/*------------------  LOCAL DRIVERS ---------------------------*/
#include <LCD4Bit.c>    // Our Library undertest 

/*-------- Global Veriable Defination Area ---------------------*/
#define __VER__ 1.0     //current example version number

/*----------- Function Defination Area --------------------------*/
void printWelcomeMessage();   //

/*------ Main Starts here --------------------------------------*/
void main(void){
   lcd_init();  // Always call this first. 
   }//while(True) ends here
}//main ends here

void printWelcomeMessage(){
   lcd_putc("\fLCD 4BIT Driver\n"); 
   printf(lcd_putc, "     V# %1.2f", __VER__);
   lcd_putc("Abdul Rehman");
   delay_ms (1000);
}Code language: PHP (php)

By Abdul Rehman

My name is Abdul Rehman and I love to do Reasearch in Embedded Systems, Artificial Intelligence, Computer Vision and Engineering related fields. With 10+ years of experience in Research and Development field in Embedded systems I touched lot of technologies including Web development, and Mobile Application development. Now with the help of Social Presence, I like to share my knowledge and to document everything I learned and still learning.

Leave a Reply

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.