0% found this document useful (0 votes)
2 views2 pages

LCD Code

The document contains C code for interfacing an LCD with a microcontroller using the 8051 architecture. It includes functions for initializing the LCD, sending commands, and displaying data. The main function initializes the LCD and displays a predefined string character by character until it reaches the null terminator.

Uploaded by

SP Ulaganathan
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views2 pages

LCD Code

The document contains C code for interfacing an LCD with a microcontroller using the 8051 architecture. It includes functions for initializing the LCD, sending commands, and displaying data. The main function initializes the LCD and displays a predefined string character by character until it reaches the null terminator.

Uploaded by

SP Ulaganathan
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

#include<reg51.

h>

#define display_port P2 //Data pins connected to port 2 on microcontroller

Sbit rs P3^2; //RS pin connected to pin 2 of port 3

Sbit rw P3^3;

Void msdelay(unsigned int time)

Unsigned i,j;

For(i=0;i<time;i++) for(j=0;j<1275;j++);

Void lcd_cmd(unsigned char command)

{ display port command;

Rs= 8;

Rw=0;

E=1; msdelay(1);

Void lcd_data(unsigned char disp_data) //Function to send display data to LCD

Display_port = disp_data;

R5= 1;

E=1; msdelay(1);

E=0;

} void lcd_init() //Function to prepare the LCD and get it ready

{
Lcd_cmd(0x38); // for using 2 lines and 5X7 matrix of LCD

Msdelay(10); lcd_cmd(exer); // turn display ON, cursor blinking

Msdelay(10);

Lcd_cmd(exe1); //clear screen

Msdelay(10);

Lcd_cmd(0x81); // bring cursor to position 1 of line 1 msdelay(10);

Void main()

Unsigned char a[100]=”ULAGANATHAN SP”; //string of 14 characters with a


null terminator.

Int 1-0; lcd_init();

While(a[1] != ‘\0’) // searching the null terminator in the sentence

{ lcd_data(a[1]); 1++;

Msdelay(50);

You might also like