problems with DS1307 clock when power off

I set up the sketch for a clock using a DS1307. It works well, but if I take power off and on again, the clock will give the original time I set in the beginning. Is this a programming mistake or is it a failure of the DS1307?

Yes

If you post your code web will be able to help you, you probably have a line in it that setsitbtonthe time the sketch was compiled

It is not a failure of the clock device, because I used the old way: uploading the RTC sketch 1st and subsequently the display sketch. Now the info was kept and the clock runned further on the battery.
her eis the sketch that does not keep the clock running:
Here the sketch comes

#include “Wire.h”
#define DS1307_ADDRESS 0x68
byte zero = 0x00; //workaround voor melding #527
#include<LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x3F, 16, 2);

void setup() {
Wire.begin(); //Voor I2C protocol
Serial.begin(9600);//Start de seriële communicatie

lcd.backlight();
lcd.init();
setDateTime(); //Dit is een aanroep naar de functie setDateTime();
}

void loop() {
printDate();//Aanroep naar functie printDate()
delay(1000);//1000 mS = 1 seconde pauzeren
}

void setDateTime() {

byte second = 50; //0-59
byte minute = 59; //0-59
byte hour = 9; //0-23
byte weekDay = 6; //1-7 (zondag =1, maandag=2, enz)
byte monthDay = 27; //1-31
byte month = 1; //1-12
byte year = 17; //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(weekDay));
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(zero);
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 weekDay = bcdToDec(Wire.read()); //1-7 → sunday - Saturday
int monthDay = bcdToDec(Wire.read());
int month = bcdToDec(Wire.read());
int year = bcdToDec(Wire.read());

//print de datum bijv. 3/1/11 23:59:59
//Om dit te zien opent u de seriële monitor.
lcd.setCursor(0, 1);
lcd.print(monthDay);
if (month == 1) {
lcd.print(“januari,”);
}
else {
if (month == 2) {
lcd.print(“februari,”);
}
else {
if (month == 3) {
lcd.print(“maart,”);
}
else {
if (month == 4) {
lcd.print(“april,”);
}
else {
if (month == 5) {
lcd.print(“mei,”);
}
else {
if (month == 6) {
lcd.print(“juni,”);
}
else {
if (month == 7) {
lcd.print(“juli,”);
}
else {
if (month == 8) {
lcd.print(“augustus,”);
}
else {
if (month == 9) {
lcd.print(“september,”);
}
else {
if (month == 10) {
lcd.print(“oktober,”);
}
else {
if (month == 11) {
lcd.print(“november,”);
}
else {
if (month == 12) {
lcd.print(“december,”);
}
}
}
}
}
}
}
}
}
}
}
}
lcd.print(" 20");
lcd.print(year);
// lcd.print(":");
// if (second <=9){ lcd.print(“0”);}
// lcd.print(second);
lcd.setCursor(0, 0);
// lcd.print(",");

// lcd.print(",");
if (weekDay == 1) {
lcd.print(“Zondag,”);
}
else {
if (weekDay == 2) {
lcd.print(“Maandag,”);
}
else {
if (weekDay == 3) {
lcd.print(“Dinsdag,”);
}
else {
if (weekDay == 4) {
lcd.print(“Woensdag,”);
}
else {
if (weekDay == 5) {
lcd.print(“Donderdag,”);
}
else {
if (weekDay == 6) {
lcd.print(“Vrijdag,”);
}
else {
if (weekDay == 7) {
lcd.print(“Zaterdag,”);
}
}
}
}
}
}
}

if (hour <= 9) {
lcd.print(“0”);
}
lcd.print(hour);
//lcd.print(":");
if (minute <= 9) {
lcd.print(“0”);
}
lcd.print(minute);
if (second <= 9) {
lcd.print(“0”);
}
lcd.print(second);

//Serial.print(" ");

}

setDateTime(); //Dit is een aanroep naar de functie setDateTime();

What does setDateTime do?

(See what I did with code tags there? You could/should have done that.)