Sunday, June 7, 2015

LCD Program for 8051 Microcontroller

Embedded C program for 8051 :

how to write embedded C program for 8051 microcontroller

// program to interface 16x2 Alphanumeric LCD with 8051/ 8051
/***********************************************************/
// Auther :  Venky Naidu
// Organization: Venky's Vision IT Solutions
// Version : 2.0
/**********************************************************/
/*************** pin connections ******************************/

// lcd data pins connected to Port2
//  RS pin connected to P3.0
// RW pin connected to P3.1
// EN pin connected to P3.2

/*********************************************************/

#include<reg52.h>
sfr lcddata=0xA0; // lcd data pins DB0 to DB7 connected to P2.0 to P2.7
sbit RS=P3^0;
sbit RW=P3^1;
sbit EN=P3^2;

/******************** functions prototypes **********************/
void lcdinit();
void lcdcmd(unsigned char);
void lcdchar(unsigned char);
void lcdstring(unsigned char *);
void delay(unsigned int );
/********************** main function *************************/

void main()
{
    lcdinit();
    lcdcmd(0x80);
    lcdstring("VENKY'S ");
    lcdcmd(0xc0);
    lcdstring("VISION IT SOLUTIONS");
    //while(1);
}

void lcdinit()
{
    lcdcmd(0x38);
    delay(10);
    lcdcmd(0x80);
    delay(10);
    lcdcmd(0x06);
    delay(10);
    lcdcmd(0x01);
    delay(10);
    lcdcmd(0x0e);
    delay(10);
    lcdcmd(0xc0);
    delay(10);
}

void lcdcmd(unsigned char cmd)
{
    lcddata=cmd;
    rs=0;
    rw=0;
    en=1;
    delay(10);
    en=0;
}
void lcdchar(unsigned char ch)
{
    lcddata=ch;
    rs=1;
    rw=0;
    en=1;
    delay(10);
    en=0;
}
void lcdstring(unsigned char *str)
{
    while(*str!='\0')
    {
        lcdchar(*str++);
    }
}
void delay(unsigned int i)
{
    unsigned int j;
    for(i;i>0;i--)
    for(j=0;j<=1275;j++);
}



//////////////////////////////////////// out put checking using Proteus 7 ////////////////////////////////

connect the pins with 8051 as shown in above fig :

 

No comments:

Post a Comment

Comment here....