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
You are here: Home / Topics / eeprom 24c02 with 89v51rd2

eeprom 24c02 with 89v51rd2

|

Microcontroller › 8051 › eeprom 24c02 with 89v51rd2

  • This topic has 1 reply, 2 voices, and was last updated 8 years, 5 months ago by AJISH ALFRED.
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • February 25, 2014 at 12:29 pm #2898
    Amit Raijade
    Participant

    hello frnds..

     

    i am using above mentioned modules

     

    i just want to check whether my code is right wrong or will it run…because it is not showing response at the time of viewing response on seven segment display.

     

    here is my code.

     

    #include<reg51.h>
     
    sbit  sda =P3^7;
    sbit  scl =P3^6;
     
    sbit    dig0            =   P2^1;
    sbit    dig1            =   P2^2;
    sbit    dig2            =   P2^3;
    sbit    dig3            =   P2^4;
    sbit    dig4            =   P2^5;
    sbit    dig5            =   P2^6;
     
    bit flag_wr,flag_rd;
    unsigned char RxByte = 0;
     
    #define PORT_SEVEN_SEG  P0    //Output Port
    #define I2C_SPEED_FACTOR 1
    #define Crystal_Value 12
    #define HalfBitDelay (500*Crystal_Value)/(12*I2C_SPEED_FACTOR)
     
    void start();
    void stop();
    void init();
    void restart();
    void ack();
    void I2C_Write_Byte(byte);
    unsigned char I2C_Read_Byte(void );
    void display(unsigned char );
     
    void delay(unsigned int d)
    {
       unsigned int i, limit;
       limit = d/15;
     
       for(i=0;i<limit;i++);
    }
     
    void main()
    {
     
    init();                 // Initialize i2c pins
     
    start();                // Send start bit on i2c
    I2C_Write_Byte(0x08);
    RxByte = I2C_Read_Byte();    // Read value from i2c
     
    ack();                  // Send ACK bit on i2c
    stop(); // Send stop bit on i2c
    //if(flag_rd)
    // display(RxByte);
    while(1);
    }
     
    void init(){
            sda = 1;
            scl = 1;
    }
     
    void start()
    {
    scl=1;
    sda=1;
    delay(HalfBitDelay);
    sda=0;
    scl=0;
    }
     
     
    void stop(){ 
    scl=1;
     sda=0;
    delay(HalfBitDelay/2);
    sda=1;
    }
     
    void restart(){
            scl = 0;
         delay(HalfBitDelay/2);
            sda = 1;
         delay(HalfBitDelay/2);
            scl = 1;
         delay(HalfBitDelay/2);
            sda = 0;
         delay(HalfBitDelay/2);
    }
     
    void ack(){
            sda = 0;
         delay(HalfBitDelay/2);
            scl = 1;
         delay(HalfBitDelay/2);
            scl = 0;
         delay(HalfBitDelay/2);
            sda = 1;
         delay(HalfBitDelay/2);
    }
     
    void I2C_Write_Byte(unsigned char Byte)
    {
    unsigned char i;
     
    for(i=0;i<8;i++)
    {
    scl=0;
        delay(HalfBitDelay/2);
    if((Byte<<i)&0x80)  
    sda=1;
    else
    sda=0;
        delay(HalfBitDelay/2);
      scl=1;
        delay(HalfBitDelay/2);
        }
    flag_wr = 1;
    }
     
    unsigned char I2C_Read_Byte(void)
    {
    unsigned char i, d, RxData = 0;
     
    for(i=0;i<8;i++)
    {
    scl=0; // Make SCK pin low
    sda=1; // Don’t drive SDA 
    delay(HalfBitDelay); // Half bit delay
    scl=1; // Make SCK pin high
    delay(HalfBitDelay/2); // 1/4 bit delay
    d = sda;    // Capture Received Bit
    RxData = RxData|(d<<(7-i));   // Copy it in RxData
    delay(HalfBitDelay/2); // 1/4 bit delay
     
    }
        
        return RxData; // Return received byte
     flag_rd = 1;
    }
    /*
    void display(unsigned char RxByte )
    {      
    dig0 = 0;
    dig1 = 1; 
    dig2 = 1;          
    dig3 = 1; 
    dig4 = 1; 
    dig5 = 1; 
         
        PORT_SEVEN_SEG = RxByte; */
     
    }    
     
    on my card there are 6 displays thats why this dig0 to dig5  
    March 1, 2014 at 4:55 am #11135
    AJISH ALFRED
    Participant

    Hi,

    The code itself dosen’t mean anything. Please share the details of the hardware including circuit diagram and a brief idea about how you expect it to work.

  • 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

  • How know if solder iron has good quality tip? August 18, 2022
  • How does a transistor works as a switch? August 18, 2022
  • Peltier control August 18, 2022
  • How to set USB port as RS-485 entrance? How to interpret Growatt solar inverter commands? August 18, 2022
  • Component Identification August 18, 2022

Stay Up To Date

Newsletter Signup
EngineersGarage

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