RTC suddenly changed date and time and is static now?

Components:
2004 LCD
1302 RTC
Pro Micro

The date and time have been working for a while now but suddenly it changed and only displays 17:30, 29/04/2043, which is nowhere close to the actual time and date. What happened to make it changed? The only thing I've done recently is change the usb cable used to provide power to the pro micro.

Here is the code:

#include <ThreeWire.h>  
#include <RtcDS1302.h>
#include <Wire.h> 
#include <LiquidCrystal_I2C.h>
 
ThreeWire myWire(A2, A0, A1); // IO, SCLK, CE
RtcDS1302<ThreeWire> Rtc(myWire);
LiquidCrystal_I2C lcd(0x27,20,4);  // set the LCD address to 0x27
 
 
byte smile[8] = 
 
              {
                B00000,
                B00000,
                B01010,
                B00000,
                B10001,
                B01110,
                B00000,
                B00000
              };
 
              
void setup(){
    Serial.begin(57600);
    Serial.print("compiled: ");
    Serial.print(__DATE__);
    Serial.println(__TIME__);
 
    Rtc.Begin();
    RtcDateTime compiled = RtcDateTime(__DATE__, __TIME__);
    printDateTime(compiled);
    Serial.println();
 
    if (!Rtc.IsDateTimeValid()) {
        // Common Causes: 1) first time you ran and the device wasn't running yet 2) the battery on the device is low or even missing
        Serial.println("RTC lost confidence in the DateTime!");
        Rtc.SetDateTime(compiled);
    }
 
    if (Rtc.GetIsWriteProtected()) {
        Serial.println("RTC was write protected, enabling writing now");
        Rtc.SetIsWriteProtected(false);
    }
 
    if (!Rtc.GetIsRunning()) {
        Serial.println("RTC was not actively running, starting now");
        Rtc.SetIsRunning(true);
    }
 
    RtcDateTime now = Rtc.GetDateTime();
    if (now < compiled) {
        Serial.println("RTC is older than compile time!  (Updating DateTime)");
        Rtc.SetDateTime(compiled);
    }
    else if (now > compiled)
        Serial.println("RTC is newer than compile time. (this is expected)");
    else
        Serial.println("RTC is the same as compile time! (not expected but all is fine)");
  
  lcd.init();  //initialize the lcd
  lcd.backlight(); 
  lcd.createChar(1, smile);
  
  lcd.setCursor ( 0, 2 );          
  lcd.write(1);
  lcd.setCursor (2, 2);
  lcd.print("You've got this!");
  lcd.setCursor (19, 2);
  lcd.write(1); 
  
  
  lcd.setCursor ( 1, 3 );            
  lcd.print("Fruit/Veg? Vit D?");
 
}
/*********************************************************/
void loop() {
      RtcDateTime now = Rtc.GetDateTime();
      now -= 60;
    printDateTime(now);
    if (!now.IsValid()) {
        // Common Causes: 1) the battery on the device is low or even missing and the power line was disconnected
        Serial.println("RTC lost confidence in the DateTime!");
    }
    delay(1000);
}
  
  #define countof(a) (sizeof(a) / sizeof(a[0]))
 
  void printDateTime(const RtcDateTime& dt) {
      char datestring[20];
      snprintf_P(datestring, 
              countof(datestring),
              PSTR("%02u/%02u/%04u"),
              dt.Day(), dt.Month(), dt.Year());
      
      char timestring[20];
      snprintf_P(timestring,
                countof(timestring),
                PSTR("%02u:%02u"),
                dt.Hour(), dt.Minute());
 
      int dow = dt.DayOfWeek();
      
      switch(dow){
     case 1:
     lcd.setCursor(17,0);
     lcd.print("Mon");
     break;
     case 2:
     lcd.setCursor(17,0);
     lcd.print("Tue");
     break;
     case 3:
     lcd.setCursor(17,0);
     lcd.print("Wed");
     break;
     case 4:
     lcd.setCursor(17,0);
     lcd.print("Thu");
     break;
     case 5:
     lcd.setCursor(17,0);
     lcd.print("Fri");
     break;
     case 6:
     lcd.setCursor(17,0);
     lcd.print("Sat");
     break;
     case 0:
     lcd.setCursor(17,0);
     lcd.print("Sun");
    
     break;}
 
    
 
    lcd.setCursor ( 7, 0 );
    lcd.print(timestring);
    lcd.setCursor (5, 1);
    lcd.print(datestring);
 
    if (int(dt.Hour()) <= 07){
        lcd.noBacklight();
    }
}

Did you check the battery?

@aarg no I haven't, I only recently got the RTC component though, aren't the batteries supposed to last quite a while? How would I test the battery?

By replacing it with a new one.

What type of battery do you have? The DS1302 has built-in trickle charge capability, if that is turned on it may damage a non-rechargeable battery.

david_2018:
What type of battery do you have? The DS1302 has built-in trickle charge capability, if that is turned on it may damage a non-rechargeable battery.

It's a CR2032

Thinking will not get you out of this. Just change the battery.

@OP,
If the battery replaced or removed you need to write a sketch to set time again.

abdelhmimas:
@OP,
If the battery replaced or removed you need to write a sketch to set time again.

The sketch already sets the time from the compile time variable. Even if it isn't set, it will increment.

aarg:
The sketch already sets the time from the compile time variable. Even if it isn't set, it will increment.

You are right, I saw it now.

aarg:
The sketch already sets the time from the compile time variable. Even if it isn't set, it will increment.

So what happens when you recompile and upload the sketch?

aarg:
Thinking will not get you out of this. Just change the battery.

Ok, just switched to another RTC and it's still doing the same thing after a reupload to the board.

abdelhmimas:
So what happens when you recompile and upload the sketch?

Nothing changes.

Show us images of your actual wiring.

You have a bunch of debug output but you have not shown any to us. Open Serial Monitor and reset the board. Copy and paste the text you see in Serial Monitor to a post here.

Have you tried to reset the DS1302 by removing the battery and reinsert it?

dentonn:
Ok, just switched to another RTC and it's still doing the same thing after a reupload to the board.Nothing changes.

It could be the initialization data in the sketch.
As it was mentioned before, the sketch will set the current date. You need to open serial monitor and watch what you are sending to set the current date.

aarg:
Show us images of your actual wiring.

You were right-ish, one of the wires came loose. Fixed that and it's back to working! Thanks!

I'm not sure why people were suggesting it was an issue with the sketch when it was working before and it suddenly stopped working without any changes to the sketch though. Does it happen that sketch issues happen when no changes to the sketch have been made?

@dentonn,
well, without knowing which wire, it will be very hard to tell.

dentonn:
I'm not sure why people were suggesting it was an issue with the sketch when it was working before and it suddenly stopped working without any changes to the sketch though. Does it happen that sketch issues happen when no changes to the sketch have been made?

Yes. For example, if your RTC lost power you would then be executing a part of the sketch that doesn't get executed when the RTC is running. If there were a programming error in that part of the sketch, the problem would only be seen after the RTC lost power. The sketch has not changed but a new programming error appears.