1. Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.
    Dismiss Notice

Interface a character LCD display to PIC microcontroller

[B]Introduction[/B] An HD44780 Character LCD display device is designed for interfacing with embed

  1. rajbex
    An HD44780 Character LCD display device is designed for interfacing with embedded systems. These screens come in a variety of configurations including 8x1, which is one row of eight characters, 16x2, and 20x4. These LCDs can come with or without backlights, which may be LED, fluorescent, or electroluminescent. They use a standard 14-pin interface and those with backlights have 16 pins. The pinouts are shown in figure below.

    I am going to show you how to interface such a LCD to a PIC microcontroller (PIC16F628A). The programming for PIC will be done in mikroC (a C compiler for PIC from mikroelektronika). mikroC has in-built library routines for handling LCD commands and data transfer. The circuit diagram shown below is for 4-bit operation mode of LCD. This means that display data and command from microcontroller to the LCD are sent using only the most significant 4-bits. This way, every data and command (both 8-bits) can be sent in two steps: Send High Nibble first and then send Low Nibble. This saves I/O pins of microcontroller.

    View attachment Screen shot 2012-04-26 at 2.08.11 PM.png

    Code (text):
     * Project name:
         Test LCD in 4-bit mode
     * Copyright:
         (c) Rajendra Bhatt, 2009.
     * Description:
         This code demonstrates how to display test message on a LCD which
         is connected to PIC16F628A through PORTB. D4-D7 pins of LCD are
         connected to RB4-RB7, whereas RS and EN pins connected to RA0 and RA1
         MCU:             PIC16F628A
         Oscillator:      XT, 4.0 MHz
         Configuration: MCLR Enabled, WDT OFF
    // LCD module connections
    sbit LCD_RS at RA0_bit;
    sbit LCD_EN at RA1_bit;
    sbit LCD_D4 at RB4_bit;
    sbit LCD_D5 at RB5_bit;
    sbit LCD_D6 at RB6_bit;
    sbit LCD_D7 at RB7_bit;
    sbit LCD_RS_Direction at TRISA0_bit;
    sbit LCD_EN_Direction at TRISA1_bit;
    sbit LCD_D4_Direction at TRISB4_bit;
    sbit LCD_D5_Direction at TRISB5_bit;
    sbit LCD_D6_Direction at TRISB6_bit;
    sbit LCD_D7_Direction at TRISB7_bit;
    // End LCD module connections
    // Define Messages
     char message1[] = "Testing LCD";
     char message2[] = "using PIC16F628A";
     char message3[] = "Test Successful!";
     char message4[] = "2009/09/18";
    void main() {
      CMCON  |= 7;                       // Disable Comparators
      Lcd_Init();                        // Initialize LCD
      do {
      Lcd_Cmd(_LCD_CLEAR);               // CLEAR display
      Lcd_Cmd(_LCD_CURSOR_OFF);          // Cursor off
      Lcd_Out(1,1,message1);             // Write message1 in 1st row
      Lcd_Out(2,1,message2);             // Write message1 in 2nd row
      Lcd_Cmd(_LCD_CLEAR);               // Clear display
      Lcd_Out(1,1,message3);             // Write message3 in 1st row
      } while(1);
    More mikroC code @ http://pic16f628a.blogspot.com