Saturday, July 24, 2010

Interface a HD44780 Character LCD with a PIC Microcontroller

An HD44780 Character LCD is a liquid crystal display (LCD) display device 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. The most commonly manufactured configuration is 40x4 characters, which requires two individually addressable HD44780 controllers with expansion chips as the HD44780 can only address up to 80 characters.

These LCD screens are limited to text only and are often used in copiers, fax machines, laser printers, industrial test equipment, networking equipment such as routers and storage devices. Character LCDs can come with or without backlights, which may be LED, fluorescent, or electroluminescent. Character LCDs 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). The circuit diagram is shown below:

The software is here:

 Note: Never forget to disable the comparator functions on PORTA.0, 1, 2, 3 pins if you are going to use those pins as digital I/O.
 * Project name:
     Test LCD in 4-bit mode
  * 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
// 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);


Post a Comment