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 / how to send and receive 2digit data from eeprom 24c02 from array

how to send and receive 2digit data from eeprom 24c02 from array

|

Microcontroller › 8051 › how to send and receive 2digit data from eeprom 24c02 from array

  • This topic has 2 replies, 2 voices, and was last updated 14 years, 1 month ago by vignesh.
Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • February 5, 2012 at 9:59 am #1681
    vignesh
    Participant

    how to send and receive 2digit data from eeprom 24c02 from array

     

    dis is the program which is i got through the website

     

    #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^6;
    unsigned char reead,write,write2,i,j;
    unsigned int temp;
    void delay(unsigned int count)
    {
     int i,j;
     for(i=0;i<count;i++)
      for(j=0;j<1275;j++);
    }
    void lcd_command(unsigned char comm)
    {
     lcd_data_pin=comm;
     en=1;
     rs=0;
     rw=0;
     delay(1);
     en=0;
    }
    void lcd_data(unsigned char disp)
    {
     lcd_data_pin=disp;
     en=1;
     rs=1;
     rw=0;
     delay(1);
     en=0;
    }
    lcd_dataa(unsigned char *disp)
    {
     int x;
     for(x=0;disp[x]!=0;x++)
     {
      lcd_data(disp[x]);
     }
    }
    void lcd_ini()
    {
     lcd_command(0x38);    // for using 8-bit 2 row LCD
     delay(5);
     lcd_command(0x0F);        // for display on, cursor blinking
     delay(5);
     lcd_command(0x80);
     delay(5);
    }
    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;    //Returns 8 bit data here
    }  
    void save()     //save in EEPROM
    { 
     start();
     send_byte(0xA0);      //device address
     aknowledge();
     send_byte(0x00);      //word address
     aknowledge();
     send_byte(5);
     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<=55)
     {
      led=0;
      delay(100);
      led=1;
      delay(100);
      write=i+48;
      lcd_command(0xC6);
      lcd_data(write); 
     }
     else
      led=1;
     if(j<=55)
     {
      lcd_command(0xC7);
      write=j+48;
      lcd_data(write);
     }
     aknowledge();
    }

    void main()
    {
     lcd_ini();
     lcd_dataa(“Sent :”);
     lcd_command(0xC0);
     lcd_dataa(“Read :”);
     temp=0;
     while(1)
     {
      save();
      Read();
     }
    }

     

    please help me to send a array data like dis

     

    array[2]=”12″

    February 26, 2012 at 6:15 pm #7198
    amardeep
    Participant

    hi 
    you have to send data in 8 bit pattren like 0x95 in hex number system

     

     

    Example :

    unsigned char array[5]={5,10,8,3}

     

     

    void save()     //save in EEPROM
    { 
     start();
     send_byte(0xA0);      //device address
     aknowledge();
     send_byte(0x00);      //word address
     aknowledge();
     send_byte(array[0]);
     aknowledge();
     send_byte(array[1]);
     aknowledge();

     send_byte(array[2]);
     aknowledge();

     send_byte(array[3]);
     aknowledge();
     stop();           // don’t forget to stop the communication

    this way data will be write in sequential manner

    Hope it will help U :)  

    February 27, 2012 at 3:20 pm #7200
    vignesh
    Participant

    thank u very much!!! its working

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

RSS Recent Posts

  • isolating S-params in of PCB board without connectors April 11, 2026
  • Assistance locating a 'trail' camera gadget, please ? April 10, 2026
  • Raise your hand if your car had one of these: April 10, 2026
  • Some opamp advice please April 10, 2026
  • Voltage comparator circuit verification April 10, 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