Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
MCP7940.h
00001 #ifndef __MCP7940_H__ 00002 #define __MCP7940_H__ 00003 00004 #include "mbed.h" 00005 /** MCP7940 class. 00006 * Interface to the MCP7940 allowing you to get and set the time 00007 * Example: 00008 * @code 00009 * #include "mbed.h" 00010 * #include "MCP7940.h" 00011 * 00012 * MCP7940 clock(PinName sda, PinName scl); 00013 * 00014 * int main() { 00015 * 00016 * clock.setTime(2015, 9, 26, 22, 50); 00017 * clock.StartClock(); 00018 * printf("%s \r\n" clock.TimeStamp()); 00019 * //or 00020 * clock.getTime(); 00021 * printf("Day: %i, Month: %i, Year %i \r\n" clock.Day(), clock.Month(), clock.Year()); 00022 * } 00023 * @endcode 00024 */ 00025 00026 class MCP7940 00027 { 00028 public: 00029 /** Constructor 00030 * Start year will default to 2000. 00031 * @param sda I2C SDA pin 00032 * @param scl I2C SCL pin 00033 */ 00034 MCP7940(PinName sda, PinName scl); 00035 /** Constructor 00036 * Start year will default to 2000. 00037 * @param sda I2C SDA pin 00038 * @param scl I2C SCL pin 00039 * @param StarYear The start year for you calender. The MCP7940 defines years as XX, so that this library can give XXXX years you need to set your year 0, ie 2000 00040 */ 00041 MCP7940(PinName sda, PinName scl, int StartYear); 00042 MCP7940(); 00043 /** Day 00044 * Note getTime() must have been called to update the value of day. 00045 * @returns The day of the month 00046 */ 00047 int Day(); 00048 /** Month 00049 * Note getTime() must have been called to update the value of day. 00050 * @returns The month. 00051 */ 00052 int Month(); 00053 /** Year 00054 * Note getTime() must have been called to update the value of day. 00055 * @returns The Year as XXXX = StartYear + XX as in MCP7940 00056 */ 00057 int Year(); 00058 /** Hour 00059 * Note getTime() must have been called to update the value of day. 00060 * @returns the hour 00061 */ 00062 int Hour(); 00063 /** Minutes 00064 * Note getTime() must have been called to update the value of day. 00065 * @returns Minutes 00066 */ 00067 int Minutes(); 00068 /** Seconds 00069 * Note getTime() must have been called to update the value of day. 00070 * @returns seconds 00071 */ 00072 int Seconds(); 00073 /** MilliSeconds 00074 * Note getTime() must have been called to update the value of day. 00075 * Included for completeness - but MCP7940 doesn't have a mS counter 00076 * @returns Milliseconds = 0 for MCP7940 00077 */ 00078 int MilliSeconds(); 00079 /** DayOfWeek 00080 * Note getTime() must have been called to update the value of day. 00081 * @returns The day of the week, a number 1-7. This is user defined 00082 */ 00083 int DayOfWeek(); 00084 00085 /** SetTime 00086 * Transfers the values of the time members into the MCP7940. Use one of the other setTime functions 00087 */ 00088 int setTime(); 00089 /** SetTime 00090 * Transfers the values of the time members into the MCP7940. Use one of the other setTime functions 00091 * @param Year the year in YYYY 00092 * @param Month 00093 * @param Day the Day of the month 00094 * @param Hour 00095 * @param Minutes 00096 */ 00097 int setTime(int Year, int Month, int Day, int Hour, int Mins); 00098 /** SetTime 00099 * Transfers the values of the time members into the MCP7940. Use one of the other setTime functions 00100 * @param Year the year in YYYY 00101 * @param Month 00102 * @param Day the Day of the month 00103 * @param Hour 00104 * @param Minutes 00105 * @param Secs 00106 */ 00107 int setTime(int Year, int Month, int Day, int Hour, int Mins, int Secs); 00108 /** SetTime 00109 * Transfers the values of the time members into the MCP7940. Use one of the other setTime functions 00110 * @param Year the year in YYYY 00111 * @param Month 00112 * @param Day the Day of the month 00113 * @param Hour 00114 * @param Minutes 00115 * @param Secs 00116 * @param MiliSecs - note only for completeness and future extension as MCP7940 doesn't include mS 00117 */ 00118 int setTime(int Year, int Month, int Day, int Hour, int Mins, int Secs, int MiliSecs); 00119 /** SetTime 00120 * Transfers the values of the time members into the MCP7940. Use one of the other setTime functions 00121 * @param Year the year in YYYY 00122 * @param Month 00123 * @param Day the Day of the month 00124 * @param Hour 00125 * @param Minutes 00126 * @param Secs 00127 * @param MiliSecs - note only for completeness and future extension as MCP7940 doesn't include mS 00128 * @param DayOfWeek - the day of the week as a number 1-7, User defined 00129 */ 00130 int setTime(int Year, int Month, int Day, int Hour, int Mins, int Secs, int MiliSecs, int DayOfWeek); 00131 00132 int setDefaultTime(); 00133 /** getTime 00134 * Loads the time from the MCP7940 so its upto date and can be accessed by the Day(), Month()... functions 00135 */ 00136 int getTime(); 00137 /** StartClock 00138 * Clears and sets bit 7 of register 0x00 to start the clock. Keeps the current values of 0x00 bits 0-6 00139 */ 00140 void StartClock(); 00141 00142 /** TimeStamp 00143 * getTime() is called within this function so does not need to be called from code. 00144 * @returns A pointer to a time stamp as YYYY-MM-DDTHH:MM:SS 00145 */ 00146 char * TimeStamp(); 00147 void TimeStamp(char * buf); 00148 void niceTimeStamp(char * buf); 00149 void niceDate(char * buf); 00150 void niceTime(char * buf); 00151 00152 private: 00153 char _TimeStamp[20]; 00154 int _Day; 00155 int _Month; 00156 int _Year; 00157 int _Hour; 00158 int _Minutes; 00159 int _Seconds; 00160 int _MilliSeconds; 00161 int _DayOfWeek; 00162 00163 int _YearStart; 00164 00165 protected: 00166 I2C Clock; 00167 char IntToBCD(char Data); 00168 char BCDtoInt(char Data); 00169 int _addr; 00170 00171 00172 }; 00173 00174 00175 #endif
Generated on Thu Jul 21 2022 08:18:33 by
1.7.2