EDF - OnePIC MCU  v1.1.0
source/base/include/OnePIC_rtcc.h
Go to the documentation of this file.
00001 /*****************************************************************************
00002  *
00003  * Real Time Clock Calender
00004  *
00005  *****************************************************************************
00006  * FileName:        rtcc.h
00007  * Dependencies:    
00008  * Processor:       PIC24, PIC32
00009  * Compiler:            C30 xx.xx or higher, C32
00010  * Linker:          MPLINK 03.20.01 or higher, MPLINK32
00011  * Company:         Microchip Technology Incorporated
00012  *
00013  * Software License Agreement
00014  *
00015  * The software supplied herewith by Microchip Technology Incorporated
00016  * (the "Company") is intended and supplied to you, the Company's
00017  * customer, for use solely and exclusively with products manufactured
00018  * by the Company. 
00019  *
00020  * The software is owned by the Company and/or its supplier, and is 
00021  * protected under applicable copyright laws. All rights are reserved. 
00022  * Any use in violation of the foregoing restrictions may subject the 
00023  * user to criminal sanctions under applicable laws, as well as to 
00024  * civil liability for the breach of the terms and conditions of this 
00025  * license.
00026  *
00027  * THIS SOFTWARE IS PROVIDED IN AN "AS IS" CONDITION. NO WARRANTIES, 
00028  * WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED 
00029  * TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 
00030  * PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. THE COMPANY SHALL NOT, 
00031  * IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL OR 
00032  * CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
00033  *
00034  *
00035  * Author               Date        Comment
00036  *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
00037  * Chris Valenti                05-26-05        ...     
00038  * Ross Fosler                  06-06-2005      Several changes
00039  * Anton Alkhimenok     10-21-2005  Get/Set functions
00040  * Anton Alkhimenok     02-07-2008  PIC32 support
00041  *****************************************************************************/
00042 
00050 // Setup clock
00051 extern void RTCCInit(void);
00052 // Must be called periodically to refresh time and date strings
00053 extern void RTCCProcessEvents(void);
00054 // Write changed time and date to clock registers
00055 extern void RTCCSet(void);
00056 
00057 
00102 typedef struct tagRTCC{
00103     unsigned char sec : 7;
00104     unsigned char start : 1;
00105     unsigned char min : 7;
00106     unsigned char res1 : 1;
00107     unsigned char hr : 6;
00108     unsigned char time12 : 1;
00109     unsigned char res2 : 1;
00110     unsigned char wkd : 3;
00111     unsigned char vbatEn : 1;
00112     unsigned char vbat : 1;
00113     unsigned char oscOn : 1;
00114     unsigned char res3 : 2;
00115     unsigned char day : 6;
00116     unsigned char res4 : 2;
00117     unsigned char mth : 5;
00118     unsigned char leapyear : 1;
00119     unsigned char res5 : 2;
00120     unsigned char yr;
00121 } RTCC;
00122 
00123 // Gets time and date
00124 extern RTCC _time;
00125 extern RTCC _pwr_on;
00126 extern RTCC _pwr_off;
00127 
00128 // Gets time and date second time to detect overflow
00129 extern RTCC _time_chk;
00130 
00131 // Prevents updating of _time and _time_chk
00132 extern unsigned char _rtcc_flag;
00133 
00134 // _time_str and _date_str contain current time and date strings
00135 extern char _day_time_str[16]; // Sat 10:01:15
00136 extern char _date_str[16]; // Sep 30, 2005
00137 extern char _time_str[9];
00138 // Macros and functions to get/verify and set time and date
00139 extern void RTCCSetBinSec(unsigned char Sec);
00140 extern void RTCCSetBinMin(unsigned char Min);
00141 extern void RTCCSetBinHour(unsigned char Hour);
00142 extern void RTCCSetBinDay(unsigned char Day);
00143 extern void RTCCSetBinMonth(unsigned char Month);
00144 
00145 // Set a new year value and correct Feb 29 for none leap year
00146 extern void RTCCSetBinYear(unsigned char Year);
00147 
00148 extern void RTCCReadTime(RTCC *t);
00149 
00150 // Reads current year, month, day, calculates and set week day
00151 extern void RTCCCalculateWeekDay(void);
00152 
00153 
00154 #define mRTCCInit() RTCCInit() 
00155 #define mRTCCSet()  RTCCSet() 
00156 #define mRTCCGetSec()   _time_chk.sec 
00157 #define mRTCCGetMin()   _time_chk.min 
00158 #define mRTCCGetHour()  _time_chk.hr 
00159 #define mRTCCGetWkDay() (_time_chk.wkd-1) 
00160 #define mRTCCGetDay()   _time_chk.day 
00161 #define mRTCCGetMonth() _time_chk.mth 
00162 #define mRTCCGetYear()  _time_chk.yr 
00165 #define mRTCCSetSec(__rtccdat) \
00166     _time_chk.sec = __rtccdat; \
00167     _rtcc_flag = 1;
00168 
00169 #define mRTCCSetMin(__rtccdat) \
00170     _time_chk.min = __rtccdat; \
00171     _rtcc_flag = 1;
00172 
00173 #define mRTCCSetHour(__rtccdat) \
00174     _time_chk.hr = __rtccdat;   \
00175     _rtcc_flag = 1;
00176 
00177 #define mRTCCSetWkDay(__rtccdat) \
00178     _time_chk.wkd = __rtccdat+1;   \
00179     _rtcc_flag = 1;
00180 
00181 #define mRTCCSetDay(__rtccdat) \
00182     _time_chk.day = __rtccdat; \
00183     _rtcc_flag = 1;
00184 
00185 #define mRTCCSetMonth(__rtccdat) \
00186     _time_chk.mth = __rtccdat;   \
00187     _rtcc_flag = 1;
00188 
00189 #define mRTCCSetYear(__rtccdat) \
00190     _time_chk.yr = __rtccdat;   \
00191     _rtcc_flag = 1;
00192 
00193 #define mRTCCDec2Bin(Dec)   (10 * (Dec >> 4) + (Dec & 0x0f)) 
00194 #define mRTCCBin2Dec(Bin)   (((Bin / 10) << 4) | (Bin % 10)) 
00195 #define mRTCCGetBinSec()    mRTCCDec2Bin(mRTCCGetSec()) 
00196 #define mRTCCGetBinMin()    mRTCCDec2Bin(mRTCCGetMin()) 
00197 #define mRTCCGetBinHour()   mRTCCDec2Bin(mRTCCGetHour()) 
00198 #define mRTCCGetBinWkDay()  mRTCCDec2Bin(mRTCCGetWkDay()) 
00199 #define mRTCCGetBinDay()    mRTCCDec2Bin(mRTCCGetDay()) 
00200 #define mRTCCGetBinMonth()  mRTCCDec2Bin(mRTCCGetMonth()) 
00201 #define mRTCCGetBinYear()   mRTCCDec2Bin(mRTCCGetYear()) 
00203 /*****************************************************************************
00204  * EOF
00205  *****************************************************************************/
00206