DogFlu66
Member
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(): sets the RTC to 24-hour mode.
Set_DS1302_12h(): sets the RTC to 12-hour mode.
Set_DS1302_AM_PM(bit): sets 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): writes the date and time in the DS1302.
RTC_Get_Date(day, mth, year, dow): gets the current date.
RTC_Get_Time(hr, min, sec): gets the current time.
RTC_Set_Hour(hr) 'writes the time to de DS1302.
RTC_Set_Minutes(min) 'writes the minutes to the DS1302.
RTC_Set_Seconds(sec) 'writes the seconds to the DS1302.
RTC_Write_NVRam(address, data): writes non-volatile ram for general purpose.
RTC_Read_NVRam(address): reads non-volatile ram for general purpose.
Note (2024/09/11): Update the DS1302 library because I noticed a small error in the Set_DS1302_24h() and Set_DS1302_AM_PM() functions. I also added the functions to individually modify the hour, minutes and seconds. When setting the time of the DS1302 using external keys, it is more convenient to have the functions to modify these values individually.
I attach the necessary files.
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(): sets the RTC to 24-hour mode.
Set_DS1302_12h(): sets the RTC to 12-hour mode.
Set_DS1302_AM_PM(bit): sets 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): writes the date and time in the DS1302.
RTC_Get_Date(day, mth, year, dow): gets the current date.
RTC_Get_Time(hr, min, sec): gets the current time.
RTC_Set_Hour(hr) 'writes the time to de DS1302.
RTC_Set_Minutes(min) 'writes the minutes to the DS1302.
RTC_Set_Seconds(sec) 'writes the seconds to the DS1302.
RTC_Write_NVRam(address, data): writes non-volatile ram for general purpose.
RTC_Read_NVRam(address): reads non-volatile ram for general purpose.
Note (2024/09/11): Update the DS1302 library because I noticed a small error in the Set_DS1302_24h() and Set_DS1302_AM_PM() functions. I also added the functions to individually modify the hour, minutes and seconds. When setting the time of the DS1302 using external keys, it is more convenient to have the functions to modify these values individually.
I attach the necessary files.
Attachments
Last edited: