Source code for LCD interfacing
/*------ PIN CONNECTION OF LCD WITH 8051 MCU -----------*/
LCD data lines (D0-D7) -----> ( P1.0 - P1.7 )
LCD control lines, RS(register select) ------> P2.0
RW(read write) ------> P2.1
EN( enable) -------> P2.2
/* ----------- Software for LCD interfacing-----------------------------*/
1. #include<AT89x51.h> /* header for 8051 family Micro controller*/
/* defining lcd control pin connection*/
2. #define register_select P2_0
3. #define read_write P2_1
4. #define enable P2_2
5. #define data_lines P1
/*-------declaring function or function prototyping--------*/
void millidelay(unsigned int);
void send_command(unsigned char);
void send_data(unsigned char);
void lcd_init();
void send_string(unsigned int *);
/*------ end of function prototyping------------------------*/
void main(void) // main program or program execution starting point.
{
lcd_init(); // first lcd will be initialized
send_string("HELLO WORLD"); // print and display the string.
while(1) // continue display.repeating manner.
{
}
}
void millidelay(unsigned int t) /* function that will create milly second delay*/
{
int x,y;
for(x=0;x<t;x++)
for(y=0;y<1275;y++);
}
void send_command(unsigned char x) /* function to send command to lcd*/
{
data_lines=x;
register_select=0;
read_write=0;
enable=1;
millidelay(10);
enable=0;
millidelay(10);
}
void send_data(unsigned char x) /* function to send data to the lcd*/
{
deta_lines=x;
register_select=1;
read_write=0
enable=1;
millidelay(10);
enable=0;
millidelay(1);
}
void lcd_init() /* function for lcd initialization*/
{
send_command(0x38);
send_command(0x01);
send_command(0x0E);
send_command(0x0F);
millidelay(1);
}
void send_string(unsigned char *x)
{
int x;
for(x=0;data[x]!=0;x++)
{
send_data(data[x]);
}
}