Thursday, November 12, 2015

DS3231 Library.

Professional library for projects where a RTC is implemented. Version 3.

Request a copy.
You can  send a request  to:

armicrocontroller@gmail.com

This function initializes the RTC.
DS3231_Init(void)

Example:
DS3231_Init();


This function gets the time and calendar information of the RTC.

DS3231_GetInfo(void)
Example:
DS3231_GetInfo(); 

This function can be used to configure a new time and calendar information.
DS3231_AddData(dat, inc_dec)

  • dat: This parameter selects seconds, minutes, hours, day, date, month or year.
  • 1 Seconds.
  • 2 Minutes.
  • 3 Hours.
  • 4 Day.
  • 5 Date.
  • 6 Month.
  • 7 Year.
  • inc_dec: This parameter sets the increment or decrement.
  • 1 increment.
  • 2 decrement.
Example:
DS3231_AddData(3, INC_DAT);


This function does a conversion AM to PM or PM to AM.
DS3231_AMPM(void)
Example:
DS3231_AMPM();


This function does a conversion 12hr to 24hr or 24hr to 12hr.
DS3231_HourMode(void)
Example:
DS3231_HourMode();


This function gets the full calendar. "Day Date Month Year" <<Mon 12 Jan 15>>
DS3231_GetCalendar(*p, dat)

  • *p: This parameter saves the date information in a variable.
  • dat: This parameter is used to select the day, date, month, year or the full calendar.
  • 0 Full Calendar.
  • 4 Day.
  • 5 Date.
  • 6 Month.
  • 7 Year.
  • 9 Resume Calendar.
Example:
char calendar[40];

DS3231_GetInfo();
DS3231_GetCalendar(calendar, 0);


This funtion gets the time information. "Hours:Minutes:Seconds" <<01:35:12>>
DS3231_GetTime(p1)

  • *p: This parameter saves the time information in a variable.
  • Return 0 if time is in 24 format.
  • Return 1 if time is in 24 format.
  • Return 2 if time is in AM format.
  • Return 3 if time is in PM format.
Example:
char time[10];
unsigned char ampm;

DS3231_GetInfo();
ampm = DS3231_GetTime(time);

How to use this library in a project.
Basic example:
We have  two buttons, where Button 1 selects the information to configure and Button 2 adds a new time or data information.

main()
{
 unsigned char i = 1;
 unsigned char ampm;
 char time[20];
 char calendar[40];

 DS3231_Init();
 while(1)
 {
  if(BUTTON1 == 1 && i < 8)
  {
   i++;
  }

  if(BUTTON2 == 1)
  {
   DS3231_AddData(i, INC_DAT);
  } 
  DS3231_GetInfo();
  ampm = DS3231_GetTime(time); 
  DS3231_GetCalendar(calendar, 0);
  LCD_Print(time);
  LCD_Print(calendar);
 }
}



0 comments:

Post a Comment