Interfacing LCD (4 bit Mode)
...................................................................................................................................

This is an example how to interface to the standard Hitachi-44780 LCD using an AT89C51 microcontroller and Keil as C Compiler. I use a standard 16-character by 2-line LCD module, see schematic below. Here, I use 4-bit interfacing.
Click here to Download the Program...
main.c

#include <at89x52.h>
#include "lcd.h"

main( )
{
    LCD_init();
    LCD_row1(); LCD_puts("Hello World");
    LCD_row2(); LCD_puts("Good Morning");
    while (1);
}

seven.c

#define LCD_en P3_1
#define LCD_rs P3_0
#define LCD_DELAY 2000 /* Delay for 1 ms */
#define LCD_clear() LCD_command(0x1)        /* Clear display LCD */
#define LCD_origin() LCD_command(0x2)        /* Set to origin LCD */
#define LCD_row1() LCD_command(0x80)        /* Begin at Line 1 */
#define LCD_row2() LCD_command(0xC0)   /* Begin at Line 2 */
/***************************************************
* Prototype(s)                                    *
***************************************************/
void LCD_delay(unsigned char ms);
void LCD_enable();
void LCD_command(unsigned char command);
void LCD_putc(unsigned char ascii);
void LCD_puts(unsigned char *lcd_string);
void LCD_init();

/***************************************************
* Sources                                         *
***************************************************/
void LCD_delay(unsigned char ms)
{
       unsigned char n;
       unsigned int i;
       for (n=0; n<ms; n++)
       {
               for (i=0; i<LCD_DELAY; i++); /* For 1 ms */
       }
   
}

void LCD_enable()
{
    LCD_en = 0; /* Clear bit P2.4 */
    LCD_delay(1);
    LCD_en = 1; /* Set bit P2.4 */
}

void LCD_command(unsigned char command)
{
    LCD_rs = 0; /* Clear bit P2.5 */
    P2 = (P2 & 0xF0)|((command>>4) & 0x0F);
    LCD_enable();
    P2 = (P2 & 0xF0)|(command & 0x0F);
    LCD_enable();
    LCD_delay(1);
}

void LCD_putc(unsigned char ascii)
{
    LCD_rs = 1; /* Set bit P2.5 */
    P2 = (P2 & 0xF0)|((ascii>>4) & 0x0F);
    LCD_enable();
    P2 = (P2 & 0xF0)|(ascii & 0x0F);
    LCD_enable();
    LCD_delay(1);
}

void LCD_puts(unsigned char *lcd_string)
{
       while (*lcd_string)
       {
               LCD_putc(*lcd_string++);
       }
}

void LCD_init()
{
    LCD_en = 1; /* Set bit P2.4 */
    LCD_rs = 0; /* Clear bit P2.5 */  
    LCD_command(0x33);
    LCD_command(0x32);
    LCD_command(0x28);
    LCD_command(0x0C);
    LCD_command(0x06);
    LCD_command(0x01); /* Clear */
    LCD_delay(256);
}
· Home
· 8051 Forum
· Active Topics
· 8051 Free Projects
· Blog
· Top 10
· Datasheets
· Electronic Tutorials
· Electronic Projects
· 8051 Tutorials
· 8051 Course
· 8051 Code Library
· Visual Basic for mC
· 8051 Programmer
· Assembler/IDE
· Products
· Ebooks
· Supporting Tools
· Tag Cloud
· Guest Book
· Contact Me
· Privacy policy

8051 Microcontroller Projects, free ebooks, project codes, AVR Projects, 8051 tutorials, electronic projects, ECE CSE BE final year projects, Embedded systems, AVR codes, embedded technology, LCD Interfacing tutorial,final year project ideas project downloads, engineering projects, Examples projects, 8051 Libraries, 8052, Microcontroller, Microprocessor, 8085, 8051 codes, PCB designing, Project Kits, kit