My RTC will reset to the last time that it was set to after the arduino is disconnected from the computer usb. I have checked the battery with a voltmeter and it reads 3V. Any help would greatly be appreciated!
This is the sketch I use to set the clock...
#include <LCDI2C.h>
#include <WProgram.h>
#include <Wire.h>
#include <DS1307.h>
LCDI2C lcd = LCDI2C(4,20,0x4C,1);
void setup(void) {
RTC.stop();
RTC.set(DS1307_SEC,01);
RTC.set(DS1307_MIN,32);
RTC.set(DS1307_HR,17);
RTC.set(DS1307_DOW,5);
RTC.set(DS1307_DATE,12);
RTC.set(DS1307_MTH,1);
RTC.set(DS1307_YR,12);
RTC.start();
lcd.init(); //initialize LCD
}
int High = 0;
int Low = 10000;
void loop(void){
byte i;
byte present = 0;
byte data[12];
byte addr[8];
int HighByte, LowByte, TReading, SignBit, Tc_100, Whole, Fract, minute, hour, second, date, month, year, mil_time;
char buf[12]; //used to convert int to string for displaying on LCD
//Get time from DS1307
hour = RTC.get(DS1307_HR,true);
minute = RTC.get(DS1307_MIN,false);
second = RTC.get(DS1307_SEC,false);
date = RTC.get(DS1307_DATE,false);
month = RTC.get(DS1307_MTH,false);
year = RTC.get(DS1307_YR,false);
mil_time = (hour * 100) + minute; //create military time output
lcd.setCursor(0,13);
if((hour < 10 && hour > 0) || (hour > 12 && hour - 12 < 10)){
lcd.print(" ");
}
if(hour > 12){
lcd.print(hour - 12, DEC);
}
if(hour == 0){
lcd.print(12, DEC);
}
if(hour > 0 && hour < 13){
lcd.print(hour, DEC);
}
lcd.print(":");
if(minute < 10){
lcd.print("0");
}
lcd.print(minute, DEC);
if(hour < 12 || hour == 0){
lcd.print("am");
}
else{
lcd.print("pm");
}
}