Saturday, 6 December 2014

C code for interfacing LCD with 8051 and keil

Code for interfacing LCD with 8051 and keil
In this tutorial I will discuss about how to interface LCD with 8051 using C language. I am going to write a simple code to display ‘T’, ‘R’, ‘A’, ‘C’, ‘E’ to the LCD.
I am taking AT89s52 and connect all data pins of LCD with Port one (P1) and connect RS pin to pin 0 of port 2, RW pin to pin 1 of port 2, Enable (E) pin to pin 2 of port 2.
Here is the code……………
////////////////////////////////////////////////////////////////////////////////////////////////////

#include <reg51.h>
sfr ldata = 0x90;                                                // P1=LCD data pins
sbit rs = P2^0;
sbit rw = P2^1;
sbit en = P2^2;
void main()
{
Lcdcmd(0x38);
Ms_delay(250);
Lcdcmd(0x0E);
Ms_delay(250);
Lcdcmd(0x01);
Ms_delay(250);
Lcdcmd(0x06);
Ms_delay(250);
Lcdcmd(0x86);                   // Line 1, position 6
Ms_delay(250);
Lcddata(‘T’);
Ms_delay(250);
Lcddata(‘R’);
Ms_delay(250);
Lcddata(‘A’);
Ms_delay(250);
Lcddata(‘C’);
Ms_delay(250);
Lcddata(‘E’);
Ms_delay(250);
}
Void Lcdcmd(unsigned char value)
{
Ldata = value;
rs = 0;
rw = 0;
en = 1;
Ms_delay(1);
en = 0;
return;
}
Void Lcddata (unsigned char value)
{
Ldata = value;
rs = 1;
rw = 0;
en = 1;
Ms_delay(1);
en = 0;
return;
}
Void Ms_delay(unsigned int time)
{
Unsigned int i,j;
For (i=0;i<time;i++)
For(j=0;j<1275;j++);
}






No comments:

Post a Comment