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

LCD Control Code 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)
7 views2 pages

LCD Control Code 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; // Define special function register for data port

sbit rs = P3^3; // Register select pin

sbit rw = P3^4; // Read/Write pin

sbit en = P3^5; // Enable pin

sbit busy = P1^7; // Busy flag pin

void lcdcmd(unsigned char value);

void lcddata(unsigned char value);

void lcdready(void);

void Delay(unsigned int k);

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('A');

lcddata('T');

lcddata('8');

lcddata('9');

lcddata('c');

lcddata('1');

Delay(250); // Delay for a bit before repeating

void lcdcmd(unsigned char value) {

lcdready(); // Wait until LCD is ready

ldata = value; // Send command to data register


rs = 0; // Command mode

rw = 0; // Write mode

en = 1; // Enable pulse

Delay(1); // Short delay

en = 0; // Disable

void lcddata(unsigned char value) {

lcdready(); // Wait until LCD is ready

ldata = value; // Send data to data register

rs = 1; // Data mode

rw = 0; // Write mode

en = 1; // Enable pulse

Delay(1); // Short delay

en = 0; // Disable

void lcdready(void) {

busy = 1; // Set busy flag

rs = 0; // Command mode

rw = 1; // Read mode

while (busy == 1) { // Wait while busy

en = 0; // Clear enable

Delay(1);

en = 1; // Set enable

void Delay(unsigned int k) {

int i, j;

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

for (j = 0; j < 1275; j++); // Adjust this value based on the clock speed

You might also like