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 / Code debugging problem _EEPROM using I2C and display into LCD

Code debugging problem _EEPROM using I2C and display into LCD

|

Microcontroller › 8051 › Code debugging problem _EEPROM using I2C and display into LCD

  • This topic has 1 reply, 2 voices, and was last updated 9 years, 6 months ago by Aslam Husain.
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • September 26, 2015 at 6:20 am #4031
    Shiv Kumar Mishra
    Participant
    // I want to write single byte into EEPROM and display the same in LCD. This code having some debugging problem and i am not sure wheather logic is correct written.Can anybody correct it and send at [email protected]. Please comment if needed so that it is easy to understand as i am beginner for 8051. could anybody give me code for same objective.
     
    Thanks in Advance !!!
     
    #include<reg51.h>
     
    #define lcddata P0;
     
    sbit SDA=P0^1;      // serial data line
    sbit SCL=P0^2;      // serial port line
     
     
     
    sbit rs=P2^0;    
    sbit rw=P2^1;
    sbit en=P2^2;
     
    void I2Cstart();
    void I2Cstop(); 
    void I2Cack();
    void I2Cnack();
    void I2Cwrite(unsigned char d);
    void I2Cread(unsigned char );
    void I2Creset(void);
     
    void ldata(unsigned char ddata);
    void init(void);
    void lcmd(unsigned char sdata)
    void ldisp(unsigned char location, unsigned char *d);
     
     
    unsigned char arr[]='A';
    unsigned int i;
     
     
     
     
    void msdelay(unsigned char );  // delay 
     
     
    void main (void)
    {
    unsigned char i;
    void init(void);
    I2Creset();
    I2Cstart();
    I2Cwrite(0xA0);
    I2Cack();
    I2Cwrite(0x00);
    I2Cack();
    //for(i=0; i<2; i++)
    {
    I2Cwrite(arr);
    I2Cack();
    ldisp(0x80,'c');
    lcmd(0x18);
    SCL=0;
    SDA=1;
      }
    I2Cstart();
    I2Cwrite(0xA0);
    I2Cack();
    I2Cread();
    I2Cnack();
    ldisp(0xC0,'z');
    lcmd(0x18);
     
    }
     
    void I2Cstart()    // i2c bus start condition
    {
    SDA=1;
    msdelay(10);
    SCL=1;
    msdelay(10);
    SDA=0;
    msdelay(10);
    SCL=0;
    msdelay(10);
    }
     
    void I2Cstop()     // i2c bus stop condition
    {
    SDA=0;
    msdelay(10);
    SCL=1;
    msdelay(10);
    SDA=1;
    msdelay(10);
    SCL=0;
    msdelay(10);
    }
     
    void I2Cack()   // i2c bus acknowledgementt
    {
    SDA=0;
    msdelay(10);
    SCL=1;
    msdelay(10);
    SCL=0;
      msdelay(10);
    }
     
    void I2Cnack()   // i2c bus no acknowledgement
     
    {
    SDA=1;
    msdelay(10);
    SCL=1;
    msdelay(10);
    SCL=1;
    msdelay(10);
     
    }
     
    void I2Cwrite(unsigned char d)   // i2c bus write data
    {
    unsigned char k, j=0x80;
    unsigned char c;
    for(k=0;k<8;k++)
    {
    SDA=(d&j);
    j=j>>1;
    SCL=1;
    SCL=0;;
    }
    SDA=1;
    SCL=1;
    c=SDA;
    SCL=0;
    }
     
    void I2Cread(unsigned char flag )   //i2c bus read data
    {
    unsigned char j,z=0x00,q=0x80;
     
      SDA=1;
      for(j=0;j<8;j++)
      {
    unsigned int flag;
      SCL=1;
      flag=SDA;
      if(flag=1)
      {
    z=(z|q);
    q=q>>1;
    SCL=0;
      }
         }
    }
     
    void I2Creset(void)
    {
    I2Cstart();
    delay(10);
    I2Cwrite(0xA0);
    delay(10);
    I2Cwrite(0x00);
    for(i=0;i<=25;i++);
    {
    I2Cwrite(0x00);
      }
     
    }
     
     
     
     
     
    void delay(unsigned int time)
    {
    unsigned int a,b;
    for(a=0;a<=time;a++)
    {
        for(b=0;b<=800;b++)
    {}
    }
    }
     void lcmd(unsigned char sdata)
    {
    rs=0;
    rw=0;
    en=1;
    lcddata=sdata;
    en=0;
    }
     
    void ldata(unsigned char ddata)
    {
    rs=1;
    rw=0;
    en=1;
    lcddata=ddata;
      en=0;
    }
     
    void init(void)
    {
    lcmd(0x30);
    delay(10);
    lcmd(0x38);
    delay(10);
    lcmd(0x0C);
    delay(10);
      lcmd(0x01);
      delay(10);
      lcmd(0x06);
      delay(10);
    }
     
    void ldisp(unsigned char location, unsigned char *d)
    {    
    //unsigned char a;
    lcmd(0x8F|location);
    delay(1);
    while(*d)
    {
    //a=*d;
    ldata(*d++);
        delay(10);
    }
    } 
     
     
    October 31, 2015 at 5:09 pm #13438
    Aslam Husain
    Participant

    Go through this link……

    http://www.engineersgarage.com/microcontroller/8051projects/interface-serial-eeprom-24c02-AT89C51-circuit

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

RSS Recent Posts

  • An Update On Tarrifs May 16, 2025
  • Trying to use a L9110s motor driver chip May 16, 2025
  • I want to make a CRT with some modifications But i have no Idea where to start May 16, 2025
  • Funny Images Thread! May 16, 2025
  • Need Help Figuring Out the Schematics Of Circuit Board May 16, 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