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 / Topics / programming 8×2 LCD (pc0802A)

programming 8×2 LCD (pc0802A)

|

Microcontroller › 8051 › programming 8×2 LCD (pc0802A)

  • This topic has 5 replies, 2 voices, and was last updated 13 years, 3 months ago by Shailesh Tambe.
Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • March 14, 2012 at 3:06 am #1579
    werytretr
    Participant

    Hello! anyone know how to program a 8×2 LCD (8051) with silicon laboratories? I just need to display words on the LCD.. need help urgently! please help me!! (:

    March 14, 2012 at 9:06 am #7298
    werytretr
    Participant

    how to edit from this.

     

    #include <c8051f340.h>
    #include <stdio.h>
    #include <stdlib.h>

    #define cmdport P0
    #define dataport P1
    #define q 100
    sbit rs = cmdport^4;  //register select pin
    sbit rw = cmdport^5;  // read write pin
    sbit e = cmdport^6;  //enable pin

    void delay(unsigned int msec)  // Function to provide time delay in msec.
    {
    int i,j ;
    for(i=0;i<msec;i++)
    for(j=0;j<1275;j++);
    }

    void lcdcmd(unsigned char item)  //Function to send command to LCD
    {
    dataport = item;
    rs= 0;
    rw=0;
    e=1;
    delay(1);
    e=0;
    }

    void lcddata(unsigned char item)  //Function to send data to LCD
    {
    dataport = item;
    rs= 1;
    rw=0;
    e=1;
    delay(1);
    e=0;
    }

    void main()
    {
    lcdcmd(0x38);  // for using 8-bit 2 row mode of LCD
    delay(100);
    lcdcmd(0x38);
    delay(100);
    lcdcmd(0x38);
    delay(100);
    lcdcmd(0x0E);  // turn display ON for cursor blinking
    delay(100);
    lcdcmd(0x01);  //clear screen
    delay(100);
    lcdcmd(0x06);  //display ON
    delay(100);
    lcdcmd(0x86);  // bring cursor to position 6 of line 1
    delay(100);
    lcddata(‘A’);
    }

     

    March 14, 2012 at 9:38 am #7300
    Shailesh Tambe
    Participant

    May I know, do you want to use both the lines of LCD ?

    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);
     
    }
    March 15, 2012 at 1:28 am #7303
    werytretr
    Participant

    erms, it still don’t work.. im using port 1 for PB0~PB7, P0.2 for EN, P0.1 for R/W, P0.0 for RS.. what does your b define as? is it PB0~PB7? im using this lcd, with datasheet inside.. http://singapore.rs-online.com/web/p/lcd-displays-alphanumeric/2143288/?searchTerm=214+3288&relevancy-data=636F3D3126696E3D4931384E525353746F636B4E756D6265724D504E266C753D656E266D6D3D6D61746368616C6C26706D3D5E5C647B337D5B5C732D2F255C2E5D5C647B332C347D2426706F3D313426736E3D592673743D52535F53544F434B5F4E554D424552267573743D32313420333238382677633D4E4F4E4526

     

    guess i need to add #include < c8051f340.h> as header for sure because im using silicon lab. (:

    March 16, 2012 at 12:13 pm #7306
    Shailesh Tambe
    Participant

    You have to do some necessary changes in the program as per the microcontroller, the connections and the LCD that you might be using. This program is for 16×2 LCD using P89V51RD2 Microcontroller. ‘b’ in this program is defined as PB7 to check the LCD status.

  • Author
    Posts
Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.
Log In

RSS Recent Posts

  • Adhesive Defibrillator Pad Cable June 25, 2025
  • Epson crystal oscillators June 25, 2025
  • Simple LED Analog Clock Idea June 24, 2025
  • Fun with AI and swordfish basic June 24, 2025
  • Microinverters and storeage batteries? June 23, 2025

Stay Up To Date

Newsletter Signup
EngineersGarage

Copyright © 2025 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