RTC DS1302: calendar clock with 31 non-volatile memory registers for general use.
Uses 3 pins for control: CLK (SCLK), DATA (I/O) and RST.
DATA is used to receive and transmit data. For writing, an address is sent and then the data, and when reading the device, an address is sent and the reception of the data is awaited. All this is synchronized by the CLK signal and the RST pin is previously set to 1 (start signal), to indicate that communication with the RTC (abbreviation to refer to this type of device) is going to take place.
The main functions are the following:
Init_DS1302(): initializes the RTC.
Set_DS1302_24h(): set the RTC to 24-hour mode.
Set_DS1302_12h(): set the RTC to 12-hour mode.
Set_DS1302_AM_PM(bit): set AM/PM mode.
Get_DS1302_AM_PM_24h(): gets the AM/PM/24h mode from the RTC.
RTC_Set_DateTime(day, mth, year, dow, hr, min): write the date and time in the DS1302.
RTC_Get_Date(day, mth, year, dow): get the current date.
RTC_Get_Time(hr, min, sec): get the current time.
RTC_Write_NVRam(address, data): writes non-volatile ram for general purpose.
RTC_Read_NVRam(address): reads non-volatile ram for general purpose.
I attach the necessary files.