Dear all,
problems>
1)When i working with DS1307 . I found that time has hanged at particular time. Is it possible to avoid hang operation through software. I have used external reset pin to reset RTC it worked. But i wanna know whether it possible to reset via software.If any changes to be made in below code let me know
2)while uploading below program, i found that date and time not get set properly . Let me know the reason for behaviour of RTC.
example code for rtc write given below.
#include"Wire.h"
#define DS1307_ADDRESS 0x68
byte zero = 0x00; //workaround for issue #527
void setup(){
Wire.begin();
Serial.begin(9600);
// rtc.Set_Time(13,36,0);
// rtc.Set_Date(2013,3,4);
setDateTime(); //MUST CONFIGURE IN FUNCTION
}
void loop(){
printDate();
delay(1000);
}
void setDateTime(){
byte second =45; //0-59
byte minute =59; //0-59
byte hour =12; //0-23
byte monthDay =12; //1-31
byte month =3; //1-12
byte year =13; //0-99
Wire.beginTransmission(DS1307_ADDRESS);
Wire.write(zero); //stop Oscillator
Wire.write(decToBcd(second));
Wire.write(decToBcd(minute));
Wire.write(decToBcd(hour));
Wire.write(decToBcd(monthDay));
Wire.write(decToBcd(month));
Wire.write(decToBcd(year));
Wire.write(zero); //start
Wire.endTransmission();
}
byte decToBcd(byte val){
// Convert normal decimal numbers to binary coded decimal
return ( (val/10*16) + (val%10) );
}
byte bcdToDec(byte val) {
// Convert binary coded decimal to normal decimal numbers
return ( (val/16*10) + (val%16) );
}
void printDate(){
// Reset the register pointer
Wire.beginTransmission(DS1307_ADDRESS);
Wire.write(0);
Wire.endTransmission();
Wire.requestFrom(DS1307_ADDRESS,7);
int second = bcdToDec(Wire.read());
int minute = bcdToDec(Wire.read());
int hour = bcdToDec(Wire.read() & 0b111111); //24 hour time
int monthDay = bcdToDec(Wire.read());
int month = bcdToDec(Wire.read());
int year = bcdToDec(Wire.read());
/* int second = 11;
int minute =18;
int hour = 18;
int weekDay = 1;
int monthDay = 2;
int month = 11;
int year = 12;
*/
//print the date EG 3/1/11 23:59:59
Serial.print(monthDay);
Serial.print("/");
Serial.print(month);
Serial.print("/");
Serial.print(year);
Serial.print(" ");
Serial.print(hour);
Serial.print(":");
Serial.print(minute);
Serial.print(":");
Serial.println(second);
}