m
 
(11 intermediate revisions by one other user not shown)
Line 8: Line 8:
 
{{#Widget:LibTable}}
 
{{#Widget:LibTable}}
 
|-
 
|-
|Defination || This function is used to Initialize the Ds1307 RTC.
+
|Defination ||<syntaxhighlight  lang = "c"> void RTC_Init()</syntaxhighlight>
 
|-
 
|-
 
| Input Arguments || none
 
| Input Arguments || none
Line 16: Line 16:
 
| Description || This function is used to Initialize the Ds1307 RTC.  
 
| Description || This function is used to Initialize the Ds1307 RTC.  
 
|-
 
|-
| Usage ||RTC_Init();
+
| Usage ||<syntaxhighlight  lang = "c"> RTC_Init();</syntaxhighlight>
 
|}
 
|}
  
Line 27: Line 27:
 
{{#Widget:LibTable}}
 
{{#Widget:LibTable}}
 
|-
 
|-
|Defination ||<syntaxhighlight  lang = "c"> void RTC_SetTime(uint8_t var_hour_u8, uint8_t var_min_u8, uint8_t var_sec_u8)<syntaxhighlight>
+
|Defination ||<syntaxhighlight  lang = "c"> void RTC_SetTime(uint8_t var_hour_u8, uint8_t var_min_u8, uint8_t var_sec_u8)</syntaxhighlight>
 
|-
 
|-
 
| Input Arguments || <syntaxhighlight  lang = "c">uint8_t: Hour (0x00-0x23) BCD format
 
| Input Arguments || <syntaxhighlight  lang = "c">uint8_t: Hour (0x00-0x23) BCD format
 
uint8_t: Minute (0x00-0x59) BCD format
 
uint8_t: Minute (0x00-0x59) BCD format
uint8_t: Second (0x00-0x59) BCD format<syntaxhighlight>
+
uint8_t: Second (0x00-0x59) BCD format</syntaxhighlight>
 
|-
 
|-
| Return Value||  
+
| Return Value|| none
 
|-
 
|-
| Description ||  
+
| Description || This function is used to update the Time(hh,mm,ss) of Ds1307 RTC.<br />The new time is updated into the non volatile memory of Ds1307.<br />
 +
Note: The I/P arguments should of BCD,<br />like 0x12,0x39,0x26 for 12hr,39min and 26sec.
 
|-
 
|-
| Usage ||  
+
| Usage ||<syntaxhighlight  lang = "c">RTC_SetTime(0x10,0x40,0x20); //All the arguments should be in BCD format</syntaxhighlight>
 
|}
 
|}
 
 
 
  
 
==RTC_SetDate==
 
==RTC_SetDate==
Line 47: Line 45:
 
{{#Widget:LibTable}}
 
{{#Widget:LibTable}}
 
|-
 
|-
|Defination ||  
+
|Defination ||<syntaxhighlight  lang = "c"> void RTC_SetDate(uint8_t var_day_u8, uint8_t var_month_u8, uint8_t var_year_u8)</syntaxhighlight>
 
|-
 
|-
| Input Arguments ||  
+
| Input Arguments ||<syntaxhighlight  lang = "c">uint8_t: Day(0x01-0x31) BCD format
 +
uint8_t: Month(0x01-12) BCD format
 +
uint8_t: Year(0x00-0x99) BCD format</syntaxhighlight>
 
|-
 
|-
| Return Value||  
+
| Return Value|| none
 
|-
 
|-
| Description ||  
+
| Description || This function is used to set Date(dd,mm,yy) into the Ds1307 RTC.<br />The new Date is updated into the non volatile memory of Ds1307.<br />
 +
Note: The I/P arguments should of BCD.<br />Like 0x15,0x08,0x47 for 15th day,8th month and 47th year.
 
|-
 
|-
| Usage ||  
+
| Usage ||<syntaxhighlight  lang = "c">RTC_SetDate(0x15,0x08,0x47); //All arguments should be in BCD format.</syntaxhighlight>
 
|}
 
|}
 +
  
  
Line 65: Line 67:
 
{{#Widget:LibTable}}
 
{{#Widget:LibTable}}
 
|-
 
|-
|Defination ||  
+
|Defination ||<syntaxhighlight  lang = "c">void RTC_GetTime(uint8_t *ptr_hour_u8,uint8_t *ptr_min_u8,uint8_t *ptr_sec_u8)</syntaxhighlight>
 
|-
 
|-
| Input Arguments ||  
+
| Input Arguments || <syntaxhighlight  lang = "c">uint8_t *: Address to copy Hour.
 +
uint8_t *: Address to copy Minute.
 +
uint8_t *: Address to copy Second.</syntaxhighlight>
 
|-
 
|-
| Return Value||  
+
| Return Value|| none
 
|-
 
|-
| Description ||   
+
| Description || This function is used to get the Time(hh,mm,ss) from Ds1307 RTC.<br />
 +
Note: The time read from Ds1307 will be of BCD format,<br />like 0x12,0x39,0x26 for 12hr,39min and 26sec.  
 
|-
 
|-
| Usage ||
+
| Usage ||<syntaxhighlight  lang = "c"> uint8_t hour,min,sec;
 +
RTC_GetTime(&hour,&min&sec); //Now the hour,min,sec will have the time in BCD format.</syntaxhighlight>
 
|}
 
|}
 +
  
  
Line 83: Line 90:
 
{{#Widget:LibTable}}
 
{{#Widget:LibTable}}
 
|-
 
|-
|Defination ||  
+
|Defination ||<syntaxhighlight  lang = "c">void RTC_GetDate(uint8_t *ptr_day_u8,uint8_t *ptr_month_u8,uint8_t *ptr_year_u8)</syntaxhighlight>
 
|-
 
|-
| Input Arguments ||  
+
| Input Arguments || <syntaxhighlight  lang = "c">uint8_t * : Address to copy Day.
 +
uint8_t * : Address to copy Month.
 +
uint8_t * : Address to copy Year.</syntaxhighlight>
 
|-
 
|-
| Return Value||  
+
| Return Value|| none
 
|-
 
|-
| Description ||
+
| Description ||This function is used to get the Date(d,m,y) from Ds1307 RTC.<br />
 +
Note: The date read from Ds1307 will be of BCD format,<br />
 +
like 0x15,0x08,0x47 for 15th day,8th month and 47th year.  
 
|-
 
|-
| Usage ||
+
| Usage ||<syntaxhighlight  lang = "c"> uint8_t hour,min,year;
 +
RTC_GetDate(&hour,&min&year); //Now the hour,min,year will have the Date in BCD format.</syntaxhighlight>
 
|}
 
|}
  
 +
==User Guide==
 +
<syntaxhighlight  lang = "c">
 +
/*** Program to demonstrate the  RTC library ******/
 +
#include "uart.h" //User defined UART library which contains the UART routines
 +
#include "rtc.h"    //User defined library which contains the RTC(ds1307) routines
  
  
==User Guide==
+
void main()
 +
{
 +
  unsigned char sec,min,hour,day,month,year;
 +
 
 +
 
 +
    UART_Init(9600); /* Initialize the Uart */ 
 +
    RTC_Init();      /* Initialize the RTC(ds1307)*/
 +
 
 +
 
 +
  /*note: The below RTC_SetTime()/RTC_SetDate() should be called for the first time.
 +
              Once the date and Time is set, comment the two lines ,compile and reflash the code.
 +
              Else the date,time will be updated with same values every time the controller is reset/powered ON */
 +
  RTC_SetTime(0x10,0x40,0x20);  //  10:40:20 am
 +
  RTC_SetDate(0x01,0x12,0x12);  //  1st Dec 2012
 +
 
 +
   
 +
  while(1)
 +
    {
 +
        RTC_GetDate(&day,&month,&year);  /* Read the Date from RTC(ds1307) */   
 +
        RTC_GetTime(&hour,&min,&sec);    /* Read the Time from RTC(ds1307) */
 +
 +
        UART_Printf("\n\rDate:%x/%x/%x  Time:%x:%x:%x",day,month,year,hour,min,sec);
 +
    }
 +
}
 +
</syntaxhighlight>

Latest revision as of 13:07, 14 April 2015

RTC

RTC_Init

{{#Widget:LibTable}}
Defination
 void RTC_Init()
Input Arguments none
Return Value none
Description This function is used to Initialize the Ds1307 RTC.
Usage
 RTC_Init();



RTC_SetTime

{{#Widget:LibTable}}
Defination
 void RTC_SetTime(uint8_t var_hour_u8, uint8_t var_min_u8, uint8_t var_sec_u8)
Input Arguments
uint8_t: Hour (0x00-0x23) BCD format
uint8_t: Minute (0x00-0x59) BCD format
uint8_t: Second (0x00-0x59) BCD format
Return Value none
Description This function is used to update the Time(hh,mm,ss) of Ds1307 RTC.
The new time is updated into the non volatile memory of Ds1307.

Note: The I/P arguments should of BCD,
like 0x12,0x39,0x26 for 12hr,39min and 26sec.

Usage
RTC_SetTime(0x10,0x40,0x20); //All the arguments should be in BCD format

RTC_SetDate

{{#Widget:LibTable}}
Defination
 void RTC_SetDate(uint8_t var_day_u8, uint8_t var_month_u8, uint8_t var_year_u8)
Input Arguments
uint8_t: Day(0x01-0x31) BCD format
uint8_t: Month(0x01-12) BCD format
uint8_t: Year(0x00-0x99) BCD format
Return Value none
Description This function is used to set Date(dd,mm,yy) into the Ds1307 RTC.
The new Date is updated into the non volatile memory of Ds1307.

Note: The I/P arguments should of BCD.
Like 0x15,0x08,0x47 for 15th day,8th month and 47th year.

Usage
RTC_SetDate(0x15,0x08,0x47); //All arguments should be in BCD format.



RTC_GetTime

{{#Widget:LibTable}}
Defination
void RTC_GetTime(uint8_t *ptr_hour_u8,uint8_t *ptr_min_u8,uint8_t *ptr_sec_u8)
Input Arguments
uint8_t *: Address to copy Hour.
uint8_t *: Address to copy Minute.
uint8_t *: Address to copy Second.
Return Value none
Description This function is used to get the Time(hh,mm,ss) from Ds1307 RTC.

Note: The time read from Ds1307 will be of BCD format,
like 0x12,0x39,0x26 for 12hr,39min and 26sec.

Usage
 uint8_t hour,min,sec;
RTC_GetTime(&hour,&min&sec); //Now the hour,min,sec will have the time in BCD format.



RTC_GetDate

{{#Widget:LibTable}}
Defination
void RTC_GetDate(uint8_t *ptr_day_u8,uint8_t *ptr_month_u8,uint8_t *ptr_year_u8)
Input Arguments
uint8_t * : Address to copy Day.
uint8_t * : Address to copy Month.
uint8_t * : Address to copy Year.
Return Value none
Description This function is used to get the Date(d,m,y) from Ds1307 RTC.

Note: The date read from Ds1307 will be of BCD format,
like 0x15,0x08,0x47 for 15th day,8th month and 47th year.

Usage
 uint8_t hour,min,year;
RTC_GetDate(&hour,&min&year); //Now the hour,min,year will have the Date in BCD format.

User Guide

/*** Program to demonstrate the  RTC library ******/
#include "uart.h"	//User defined UART library which contains the UART routines
#include "rtc.h"    //User defined library which contains the RTC(ds1307) routines
 
 
void main() 
{
   unsigned char sec,min,hour,day,month,year;
 
 
    UART_Init(9600); /* Initialize the Uart */  
    RTC_Init();      /* Initialize the RTC(ds1307)*/
 
 
   /*note: The below RTC_SetTime()/RTC_SetDate() should be called for the first time.
              Once the date and Time is set, comment the two lines ,compile and reflash the code.
              Else the date,time will be updated with same values every time the controller is reset/powered ON */
   RTC_SetTime(0x10,0x40,0x20);  //  10:40:20 am
   RTC_SetDate(0x01,0x12,0x12);  //  1st Dec 2012
 
 
   while(1)
    {
        RTC_GetDate(&day,&month,&year);  /* Read the Date from RTC(ds1307) */     
        RTC_GetTime(&hour,&min,&sec);    /* Read the Time from RTC(ds1307) */
 
        UART_Printf("\n\rDate:%x/%x/%x  Time:%x:%x:%x",day,month,year,hour,min,sec);
    }		
}