EngineersGarage

  • Engineers Garage Main Site
  • Visit our active EE Forums
    • EDABoard.com
    • Electro-Tech-Online
  • Projects & Tutorials
    • Circuits
    • Electronic Projects
    • Tutorials
    • Components
  • Digi-Key Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Advertise
You are here: Home / Replies / any one tell me where i

any one tell me where i

|

Microcontroller › 8051 › How to interface 4bit mode LCD to 8051 Micro controller › any one tell me where i

October 20, 2012 at 6:06 pm #8678
raju
Participant

any one tell me where i mistake in code pleace see my code.

 

#include<reg51.h>
#include<stdio.h>

sbit rs=P3^7;
sbit en=P3^6;
#define port P1

void delayms(int delay);
void lcdcmd(unsigned char l);
void lcddata(unsigned char l);
void display(unsigned char *dr);
void delay(unsigned char s);
void lcd();
void enable();
void lcdint();

void enable()
{
en=0;
delay(100);
en=1;
}
void lcdcmd(unsigned char l)
{

int s;
rs=0;
s=l;
port=((l>>4)&0x0F);
enable();
delay(1000);
enable();
port=(s&0x0F);
enable();
//enable();

}

void lcddata(unsigned char l)
{
int s;
rs=1;
s=l;
port=((l>>4)&0x0F);
enable();
delay(1000);
enable();
port=(s&0x0F);
enable();
//enable();

}

void display(unsigned char *dr)
{

while(*dr)
{
lcddata(*dr++);
}
}

void delay(unsigned char s)
{
while(s–);
}
void lcd()
{
port=0xFF;
enable();
delayms(7);
port=0x30;
enable();
delayms(5);
port=0x30;
enable();
delayms(5);
port=0x30;
enable();
delayms(5);
port=0x20;
enable();
delayms(5);

}
void lcdint()
{
lcd();
lcdcmd(0x28);
delay(100);
lcdcmd(0x0C);
delay(500);
lcdcmd(0x06);
delay(500);
//lcdcmd(0x01);
delay(500);

}

void main()
{

while(1)
{

lcdint();
lcdcmd(0x80);
lcddata(‘a’);
}
}

void delayms(int delay)
{

int i ;
for(i = 0 ; i<delay ; i++)
{
TMOD=0x01;
TH0 = 0xFC ;
TL0 = 0x17 ;
TR0 = 1 ;
while(!TF0);
TR0 = 0 ;
TF0 = 0 ;
}
}

RSS Recent Posts

  • Do i need a buffer? February 7, 2026
  • FM Radio circuits February 7, 2026
  • wall transformer polarity February 7, 2026
  • To buy or DIY? February 7, 2026
  • engineering analysis of shmidth trigger without simulation February 6, 2026

Stay Up To Date

Newsletter Signup
EngineersGarage

Copyright © 2026 WTWH Media LLC. All Rights Reserved. The material on this site may not be reproduced, distributed, transmitted, cached or otherwise used, except with the prior written permission of WTWH Media
Privacy Policy | Advertising | About Us

Search Engineers Garage

  • Engineers Garage Main Site
  • Visit our active EE Forums
    • EDABoard.com
    • Electro-Tech-Online
  • Projects & Tutorials
    • Circuits
    • Electronic Projects
    • Tutorials
    • Components
  • Digi-Key Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Advertise