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

LCD Control Program for 8051 Microcontroller

Uploaded by

surajmore2368
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)
27 views2 pages

LCD Control Program for 8051 Microcontroller

Uploaded by

surajmore2368
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>

sfr ldata = 0x90; // Special function register for the data port (P1 in this case)

sbit rs = P3^3; // Register select pin (RS)

sbit rw = P3^4; // Read/Write pin (RW)

sbit en = P3^5; // Enable pin (EN)

sbit busy = P1^7; // Busy flag pin (DB7)

void lcdcmd(unsigned char value); // Function to send commands to LCD

void lcddata(unsigned char value); // Function to send data to LCD

void lcdready(void); // Function to check if LCD is ready

void Delay(unsigned int k); // Simple delay function

void main(void) {

ldata = 0x00; // Initialize data register

lcdcmd(0x38); // Function set: 8-bit mode, 2 line, 5x7 dots

lcdcmd(0x0E); // Display ON, cursor ON, blink OFF

lcdcmd(0x06); // Entry mode set: Increment cursor

lcdcmd(0x01); // Clear display

while (1) {

lcdcmd(0x80); // Move cursor to the beginning of the first line

lcddata('W');

lcddata('E');

lcddata('L');

lcddata('C');

lcddata('O');

lcddata('M');

lcddata('E');

lcddata('_');

lcddata('T');

lcddata('O');

lcddata('_');

lcddata('S');

lcddata('G');

lcddata('M');

lcddata('R');

lcddata('P');

Delay(250); // Add a delay between writes


}

void lcdcmd(unsigned char value) {

lcdready(); // Wait until LCD is ready

ldata = value; // Send command to data port

rs = 0; // RS = 0 for command mode

rw = 0; // RW = 0 for write mode

en = 1; // Enable pin high

Delay(1); // Short delay

en = 0; // Enable pin low

void lcddata(unsigned char value) {

lcdready(); // Wait until LCD is ready

ldata = value; // Send data to data port

rs = 1; // RS = 1 for data mode

rw = 0; // RW = 0 for write mode

en = 1; // Enable pin high

Delay(1); // Short delay

en = 0; // Enable pin low

void lcdready(void) {

busy = 1; // Set busy flag

rs = 0; // RS = 0 for command mode

rw = 1; // RW = 1 for read mode

en = 1; // Enable pin high

while (busy) { // Wait while busy flag is high

en = 0; // Enable pin low

Delay(1);

en = 1; // Enable pin high

en = 0; // Disable after checking

void Delay(unsigned int k) {

unsigned int i, j;

for (i = 0; i < k; i++) {

for (j = 0; j < 1275; j++); // Adjust for clock speed

You might also like