اطلاعیه

Collapse
No announcement yet.

ds1307

Collapse
X
 
  • فیلتر
  • زمان
  • Show
Clear All
new posts

    ds1307

    سلام کسی کتابخونه ds1307 رو داره ؟

    #2
    پاسخ : ds1307

    کد:
     // Software I2C connections
    sbit Soft_I2C_Scl      at RD7_bit;
    sbit Soft_I2C_Sda      at RD6_bit;
    sbit Soft_I2C_Scl_Direction at TRISD7_bit;
    sbit Soft_I2C_Sda_Direction at TRISD6_bit;
     //End Software I2C connections
    unsigned char read_ds1307(unsigned char address );
    void write_ds1307(unsigned char address,unsigned char w_data);
    
    
    
    unsigned char read_ds1307(unsigned char address)
      {
    soft_I2C_Start();
    Soft_I2C_Write(0xd0); //address 0x68 followed by direction bit (0 for write, 1 for read) 0x68 followed by 0 --> 0xD0
    Soft_I2C_Write(address);
    soft_I2C_Stop();
    soft_I2C_Start();
    //soft_I2C_Repeated_Start();
    Soft_I2C_Write(0xd1); //0x68 followed by 1 --> 0xD1
    data1=soft_I2C_Read(0);
    soft_I2C_Stop();
    return(data1);
    }
    
     void write_ds1307(unsigned char address,unsigned char w_data)
    {
    soft_I2C_Start(); // issue I2C start signal
    //address 0x68 followed by direction bit (0 for write, 1 for read) 0x68 followed by 0 --> 0xD0
    Soft_I2C_Write(0xD0); // send byte via I2C (device address + W)
    Soft_I2C_Write(address); // send byte (address of DS1307 location)
    Soft_I2C_Write(w_data); // send data (data to be written)
    soft_I2C_Stop(); // issue I2C stop signal
    }
    
    
    
    Vvoid main()
    {
    
       Soft_I2C_Init();
    
    while()
    {
    
    
       sec=read_ds1307(0); // read second
       minute=read_ds1307(1); // read minute
       hour1=convert(hour);
    
    
                     day=read_ds1307(4);
                    year=read_ds1307(6);
          month=read_ds1307(5);
    }
    }


    اگر سوالی داشتی من در خدمتم

    دیدگاه

    لطفا صبر کنید...
    X