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 / eeprom interfacing with 8051

eeprom interfacing with 8051

|

Microcontroller › 8051 › eeprom interfacing with 8051

  • This topic has 3 replies, 2 voices, and was last updated 11 years, 2 months ago by Ashutosh Bhatt.
Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • April 9, 2014 at 8:53 pm #3032
    rohit
    Participant

    Hello sir ,i have taken a code from your site for writing and reading from eeprom and displaying it on lcd,but the code is not working in proteus.it’s not showing the result.can u please tell me what is going wrong.

    =>i am usnig 24c02b ic for eeprom

    =>if i want to store a name what should i add in the write and read function of eeprom?

    =>the code is here

    THANKS IN ADVANCE…PLEASE REPLY…

     

    #include<reg51.h>
    #include<intrins.h>   //For using [_nop_()]
    sbit sda=P1^0;
    sbit scl=P1^1;
    sbit led=P0^3;
    bit ack;
    sbit led1=P0^1;
    sfr lcd_data_pin=0xA0;//p2 port
    sfr output=0x80;//p0 port
    sbit rs=P3^0;
    sbit rw=P3^1;
    sbit en=P3^2;
    unsigned char reead,write,write2,i,j;
    unsigned int temp;
    void delay(unsigned int k)
    {
    int i,j;
    for(i=0;i<k;i++)
    for(j=0;j<1275;j++);
    }
    void lcd_command(unsigned char a)
    {
    lcd_data_pin=a;
    rs=0;
    rw=0;
    en=1;
    delay(1);
    en=0;
    }
    void lcd_data(unsigned char a)
    {
    lcd_data_pin=a;
    rs=1;
    rw=0;
    en=1;
    delay(1);
    en=0;
    }
    lcd_dataa(unsigned char *str)
    {
    int x;
    for(x=0;str[x]!=’’;x++)
    {
    lcd_data(str[x]);
    }
    }
    void lcd_ini()
    {
    lcd_command(0x38);                                        // for using 8-bit 2 row LCD 
    delay(10);
    lcd_command(0x0F);                                          // for display on, cursor blinking
    delay(10);
    lcd_command(0x80);
    delay(10);
    }
    void aknowledge()          //acknowledge condition
    {
    scl=1;
    _nop_();
    _nop_();
    scl=0;
    } 
    void start() //start condition
    {
    sda=1;
    scl=1;
    _nop_();         //No operation
    _nop_();
    sda=0;
    scl=0;
    }
    void stop() //stop condition
    {
    sda=0;
    scl=1;
    _nop_();
    _nop_(); 
    sda=1;
    scl=0;
    }
    void send_byte(unsigned char value) //send byte serially
    { 
    unsigned int i;
    unsigned char send;
    send=value;
    for(i=0;i<8;i++)
    {
    sda=send/128; //extracting MSB
    send=send<<1; //shiftng left
    scl=1;
    _nop_();
    _nop_();
    scl=0;
    }
       ack=sda; //reading acknowledge
       sda=0;
    }
    unsigned char read_byte() //reading from EEPROM serially
    {
    unsigned int i;
    sda=1;
    reead=0;
    for(i=0;i<8;i++)
    {
    reead=reead<<1;
    scl=1;
    _nop_();
    _nop_();
    if(sda==1)
    reead++;
    scl=0;
    }
    sda=0;
    return reead;
    }
    void save() //save in EEPROM
    {
    start();
    send_byte(0xA0); //device address
    aknowledge();
    send_byte(0x00); //word address
    aknowledge();
    send_byte(5); //send data
    aknowledge();
    send_byte(65);
    aknowledge();
    stop();   
     
    if(ack==0)
    {
    led1=1;
    delay(100);
    led1=0;
    delay(100);
    lcd_command(0x86);
    lcd_data(‘5’);
    lcd_command(0x87);
    lcd_data(‘A’);
    }
    else
    led1=1;
    aknowledge();
    }
    void Read()
    {
    start();
    send_byte(0xA0);
    aknowledge();
    send_byte(0x00);
    aknowledge();
    start();
    send_byte(0xA1); //device address
    aknowledge();
    i=read_byte();
    aknowledge();
    j=read_byte();
    aknowledge();
    stop();
    if(i==5)
    {
    led=0;
    delay(100);
    led=1;
    delay(100);
    write=i+48;
    lcd_command(0xC6);
    lcd_data(write);
    }
    else
    led=1;
    if(j==65)
    {
    lcd_command(0xC7);
    lcd_data(j);
    }
    aknowledge();
    }
     
    void main()
    {
    lcd_ini();
    lcd_dataa(“Sent :”);
    lcd_command(0xC0);
    lcd_dataa(“Read :”);
    temp=0;
    while(1)
    {
    save();
    Read();
    }
    }
     

     

    April 10, 2014 at 4:29 pm #11517
    Ashutosh Bhatt
    Participant

    first check your HW. is everything OK?

    then check the code in keil, compile it error free.

    then use proteus SW to make similar hardware and test software 

    April 11, 2014 at 4:18 pm #11534
    rohit
    Participant

    i have compiled and it’s error free…and the proteus hardware is also right.but the thing is,

    it is not displaying anything

    April 15, 2014 at 4:02 pm #11559
    Ashutosh Bhatt
    Participant

    if the code is working in proteus correctly then it must work in your actual HW also. 

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

RSS Recent Posts

  • Simple LED Analog Clock Idea June 22, 2025
  • Fun with AI and swordfish basic June 22, 2025
  • Is AI making embedded software developers more productive? June 22, 2025
  • Can I make two inputs from one?? June 21, 2025
  • Behlke swich June 21, 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