#include uint8_t seconds = 00;//Initialization time uint8_t minutes = 00; uint8_t hours = 11; uint8_t week = 1; uint8_t days = 30; uint8_t months = 1; uint16_t Year = 16; int bcd2bin(int temp)//BCD to decimal { int a,b,c; a=temp; b=0; if(a>=16) { while(a>=16) { a=a-16; b=b+10; c=a+b; temp=c; } } return temp; } int bin_to_bcd(int temp)//decimal to BCD { int a,b,c; a=temp; b=0; if(a>=10) { while(a>=10) { a=a-10; b=b+16; c=a+b; temp=c; } } return temp; } void setup () { Serial.begin(38400); Wire.begin(); //begin(void) {return 1;} } void loop () { /* Wire.beginTransmission(0x68);//DS1307 write the initial time Wire.write(0); Wire.requestFrom(0x68, 7); Wire.write(bin_to_bcd(seconds)); Wire.write(bin_to_bcd(minutes)); Wire.write(bin_to_bcd(hours)); Wire.write(bin_to_bcd(week)); Wire.write(bin_to_bcd(days)); Wire.write(bin_to_bcd(months)); Wire.write(bin_to_bcd(Year)); Wire.endTransmission(); */ while(1){ Wire.beginTransmission(0x68);//Send the address of DS1307 Wire.write(0);//Sending address Wire.endTransmission();//The end of the IIC communication Wire.requestFrom(0x68, 7);//IIC communication is started, you can continue to access another address (address auto increase) and the number of visits seconds = bcd2bin(Wire.read());//read time minutes = bcd2bin(Wire.read()); hours = bcd2bin(Wire.read()); week = Wire.read(); days = bcd2bin(Wire.read()); months = bcd2bin(Wire.read()); Year = bcd2bin(Wire.read()) + 2000; Serial.print(Year, DEC);//Serial display time Serial.print('/'); Serial.print(months, DEC); Serial.print('/'); Serial.print(days, DEC); Serial.print(' '); Serial.print(hours, DEC); Serial.print(':'); Serial.print(minutes, DEC); Serial.print(':'); Serial.print(seconds, DEC); Serial.println(); Serial.print(" week: "); Serial.print(week, DEC); Serial.println(); delay(1000); } }