Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Library for DS1302 clock (Oshonsoft Pic Basic Compiler).

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.
 

Attachments

  • DS1302.jpg
    DS1302.jpg
    38 KB · Views: 31
  • Test RTC DS1302.bas
    3.4 KB · Views: 22
  • _SetUpAmicus18.bas
    2.9 KB · Views: 26
  • _Pic18F26K22Library.bas
    43.3 KB · Views: 23
  • _DS1302Library.bas
    15.8 KB · Views: 18
Last edited:

Latest threads

New Articles From Microcontroller Tips

Back
Top