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 / Try out this

Try out this

|

Microcontroller › 8051 › programming 8×2 LCD (pc0802A) › Try out this

March 14, 2012 at 10:12 am #7301
Shailesh Tambe
Participant

Try out this code……………… it should work

 

 

#include<reg51.h>
#include<string.h>
 
sbit rs = P2^0;
sbit rw = P2^1;
sbit en = P2^2;
sbit  b = P1^7;
 
void writecmd(unsigned char a);
void writedat(unsigned char b);
void busy();
void writestr(unsigned char *s);
void delay(unsigned int msec);
 
void writecmd(unsigned char a)
{
 busy();
 rs=0;
 rw=0;
 P1=a;
 en=1;
 en=0;
}
 
void writedat(unsigned char b)
{
 busy();
 rs=1;
 rw=0;
 P1=b;
 en=1;
 en=0;
}
 
void busy()
{
 en=0;
 P1=0xFF;
 rs=0;
 rw=1;
 while(b==1)
 {
  en=0;
  en=1;
 }
 en=0;
}
 
void writestr(unsigned char *s)
{
 unsigned char i,len;
 len=strlen(s);
 for(i=0;i<len;i++)
 {
  writedat(*s);
  s++;
 }
}
 
void delay(unsigned int msec)
{
 int count1,count2;
 for(count1=0;count1<msec;count1++)
 for(count2=0;count2<1275;count2++);
}
 
void main()
{
 P1=0x00;
 P2=0x00;
 
  writecmd(0x3C); // Initialize the LCD
  delay(50);
  writecmd(0x0E); // turn display ON for cursor blinking
  delay(50);
  writecmd(0x01);  //Clear the LCD Screen
  delay(50);
  writecmd(0x06);
  delay(50);
  writestr(“HAPPY”);
  delay(50);
  writecmd(0xC0);
  delay(50);
  writestr(“BIRTHDAY”);
  delay(50);
  while(1);
 
}

RSS feed: Recent Posts Recent Posts

  • Will this solenoid actuator work as intended? September 13, 2026
  • NE602/SA602 Bias and Buffer circuit September 13, 2026
  • Rotary encoder with push function September 12, 2026
  • How much does generator frequency stability matter for sensitive electrical equipment? September 12, 2026
  • differential line loss question September 11, 2026

Stay Up To Date

Newsletter Signup
EngineersGarage

Copyright © 2026 Arrowfly 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 Arrowfly
Privacy Policy | Advertising

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