DS3231 and keypad questions

I want to ask why when I put "t=rtc.getTime();" in loop and the keypad won't have any reaction
but when I took off the word every thing goes right.

// MasterSwapRoles
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#include <Key.h>
#include <Keypad.h>
#include <LiquidCrystal_PCF8574.h>
#include <DS3231.h>
#include <Wire.h>
#define CE_PIN   7
#define CSN_PIN  8
#define Password_Length 5
int signalPin=9;
LiquidCrystal_PCF8574 lcd(0x27);
const byte slaveAddress[5] = {'R','x','A','A','A'}; //slaveaddress
const byte masterAddress[5] = {'T','X','a','a','a'}; //masteraddress
bool century = false;
bool h12Flag;
bool pmFlag;
Time t;
DS3231  rtc(SDA, SCL);
char Data[Password_Length];
RF24 radio(CE_PIN, CSN_PIN); // Create a Radio
byte data_count=0,master_count=0;
const byte ROWS=4;
const byte COLS=4;
char key[ROWS][COLS] = {
  {'1','2','3','A'},
  {'4','5','6','B'},
  {'7','8','9','C'},
  {'*','0','#','D'}
};
byte rowPin[ROWS]={5,4,3,2};
byte colPin[COLS]={14,15,16,17};
char dataReceived[15]; // to hold the data from the slave - must match replyData[] in the slave
bool newData = false;
char customKey=0;
unsigned long currentMillis;
unsigned long prevMillis;
unsigned long txIntervalMillis = 50; // 每50毫秒讀取一次
unsigned long before,after;
char cmd[15];
char password[4];
char test1[3]={'O','K','A'};
char test2[3]={'O','K','B'};
char test3[3]={'O','K','C'};
char test4[3]={'O','K','D'};
char failed[6]={'f','a','i','l','e','d'};
Keypad keypad = Keypad( makeKeymap(key), rowPin, colPin, 4, 4);

//============

void setup() {
    
    Serial.begin(115200);
    rtc.begin();
    lcd.begin(16,2);
    lcd.clear();
    lcd.setBacklight(255);
    lcd.setCursor(0,0);
    lcd.print("Enter Password:");
    lcd.setCursor(0,1);
    lcd.print("Pin:");
    Serial.println("MasterSwapRoles Starting");
    pinMode(signalPin, OUTPUT);
    digitalWrite(signalPin, HIGH);
    radio.begin();
    radio.setDataRate( RF24_250KBPS ); //連線速率
    radio.setPALevel(RF24_PA_MIN);//連線功率
    radio.openWritingPipe(slaveAddress);
    radio.openReadingPipe(1, masterAddress);

    radio.setRetries(3,5); // delay, count
    send(); // to get things started
    prevMillis = millis(); // set clock
}

//=============

void loop() {
    currentMillis = millis();
    t=rtc.getTime();
    char key = keypad.getKey();
    int z;
    if(currentMillis - prevMillis >=2000)//假設兩秒沒輸入 就清除數據
    {
      clearData();
      clearLCDLine(1);
    }
    if(key)//如果偵測到鍵盤有輸入
    {
       Data[data_count]=key;
       data_count++;
       for(z=4;z<=data_count+3;z++)
       {
        lcd.setCursor(z,1);
        lcd.print("*");
       }
       if (currentMillis - prevMillis >= txIntervalMillis) //每50毫秒執行一次
       {
        radio.stopListening();//寫入之前必須停止監聽
              bool rslt;
              Serial.println(Data);
                if(data_count==4)//如果輸入4位數後
                {
                    clearLCDLine(1);
                    rslt = radio.write( &Data, sizeof(Data) );//寫入密碼
                    radio.startListening();//開始監聽
                    Serial.println("Data Sent");
                    if (rslt) {
                        Serial.println("Received...OK");//接收OK
                    }
                    else {
                        Serial.println("Received...failed");//接收失敗
                        clearLCDLine(1);
                        lcd.print("R_Failed!");
                        delay(1000);
                        clearData();
                        data_count=0;
                        clearLCDLine(1);
                    }
                }
        prevMillis = millis();
      }
    }
    getData();
    
}

//====================
//備份用
void send() {
      
              radio.stopListening();
              bool rslt;
                if(data_count==4)
                {
                    rslt = radio.write( &Data, sizeof(Data) );
                    radio.startListening();
                    Serial.println("Data Sent");
                    if (rslt) {
                        Serial.println("Received...OK");
                    }
                    else {
                        Serial.println("Received...failed");
                    }
                }
}

//================

void getData() {

int a=3;
int i=0,x=0,y=0,z=0,f=0,w=0;
    if ( radio.available() )//如果通道裡有資料 
    {
        radio.read( &dataReceived, sizeof(dataReceived) );//讀取資料
        newData = true;
        for(i=0;i<a;i++)
        {
            if(dataReceived[i] == test1[i])//比對回傳值
            {
              w++;
            }
            if(dataReceived[i] == test2[i])
            {
              x++;
            }
            if(dataReceived[i] == test3[i])
            {
              y++;
            }
            if(dataReceived[i] == test4[i])
            {
              z++;
            }
            if(dataReceived[i] == failed[i])
            {
              f++;
            }
         }
         if(w==3)
         {
              
              showData1();       //
              clearData();       //如果正確
              clearLCDLine(1);   //   
           
         }
         if(x==3)
         {
              showData2();       //
              clearData();       //如果正確
              clearLCDLine(1);   //   
           
         }
         if(y==3)
         {
              showData3();       //
              clearData();       //如果正確
              clearLCDLine(1);   //   
            
         }
         if(z==3)
         {
              showData4();       //
              clearData();       //如果正確
              clearLCDLine(1);   //   
           
         }
         if(f==3)
         {
              showDatafailed();   //
              clearData();       //如果錯誤
              clearLCDLine(1);   //   
         }
      }
}

//================

void showData1() {
    if (newData == true) //當通道裡有資料時
    {
        Serial.print("Data received...");
        Serial.print(dataReceived);
        lcd.print("Hi!,Wu");
        digitalWrite(signalPin, LOW);
        delay(3000);
        Serial.println("\n");
        digitalWrite(signalPin, HIGH);
        newData = false;
    }
}
//=================

void showData2() {
    if (newData == true) //當通道裡有資料時
    {
        Serial.print("Data received...");
        Serial.print(dataReceived);
        lcd.print("Hi!,Chang");
        digitalWrite(signalPin, LOW);
        delay(3000);
        Serial.println("\n");
        digitalWrite(signalPin, HIGH);
        newData = false;
    }
}
//================

void showData3() {
    if (newData == true) //當通道裡有資料時
    {
        Serial.print("Data received...");
        Serial.print(dataReceived);
        lcd.print("Hi!,Yang");
        digitalWrite(signalPin, LOW);
        delay(3000);
        Serial.println("\n");
        digitalWrite(signalPin, HIGH);
        newData = false;
    }
}
//================

void showData4() {
    if (newData == true) //當通道裡有資料時
    {
        Serial.print("Data received...");
        Serial.print(dataReceived);
        lcd.print("Hi!,Hung");
        digitalWrite(signalPin, LOW);
        delay(3000);
        Serial.println("\n");
        digitalWrite(signalPin, HIGH);
        newData = false;
    }
}
//================
void showDatafailed() {
    if (newData == true) 
    {
        Serial.print("Data received...");
        Serial.print(dataReceived);
        lcd.print("Error!!");
        delay(2000);
        Serial.println("\n");
        newData = false;
    }
}
//================
void clearData()//清除Data陣列裡的資料
{
  while(data_count!=0)
  {
    Data[data_count--]=0;
  }
}
//=================
void clearLCDLine(int line)//清除LCD畫面
{
  lcd.setCursor(4,line);
  for(int n=0;n<12;n++)
  {
    lcd.print(" ");
  }
  lcd.setCursor(4,1);
}

what's your Arduino ?

Does your RTC work fine with your LCD (I2C, voltage conflict) ?

Arduino uno
I use LCD and RTC A4,A5 together the battery is CR2032

I don’t use that RTC library
Have you tried just with tge RTC, LCD and keypad to see if that works fine ?

Did you test the RTC with an example sketch from the RTC library?

Yes, it works fine when I test the RTC by itself.

and with the RTC, LCD and keypad ?

the keypad doesn't work when I insert the line"t=rtc.getTime();"

You seem to be including a lot of libraries. Why two RF24 libraries? What is the "Key.h" for? The SPI and Wire libraries should be included by the libraries that use them so you don't have to.

It looks like the ones you actually use directly are:

#include <RF24.h>
#include <Keypad.h>
#include <LiquidCrystal_PCF8574.h>
#include <DS3231.h>

If you comment the others out, does the sketch still compile?

Oh!! I forgot to delete it, I didn't notice that.

Yes the sketch still compile~