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.
RTC8564.cpp
00001 #include "mbed.h" 00002 #include "RTC8564.h" 00003 00004 void RTC8564::write(char address, char value) 00005 { 00006 i2c.start(); 00007 i2c.write(RTC8564NB_ADR); 00008 i2c.write(address); 00009 i2c.write(value); 00010 i2c.stop(); 00011 } 00012 00013 char RTC8564::read(char address) 00014 { 00015 char value; 00016 i2c.start(); 00017 i2c.write(RTC8564NB_ADR); 00018 i2c.write(address); 00019 i2c.start(); 00020 i2c.write(RTC8564NB_ADR | _READ); 00021 value = i2c.read(0); 00022 i2c.stop(); 00023 00024 return value; 00025 } 00026 00027 void RTC8564::time_just() 00028 { 00029 char _min, _hour; 00030 _min = read(MINUTES); 00031 if (_min >= 0x30) { 00032 _hour = read(HOURS); 00033 if (_hour == 0x23) 00034 _hour = 0x00; 00035 else if ((_hour & 0x0F) == 0x09) 00036 _hour = (_hour & 0xF0) + 0x10; 00037 else 00038 _hour = _hour + 0x01; 00039 write(HOURS, _hour); 00040 } 00041 write(MINUTES, 0x00); 00042 write(SECONDS, 0x00); 00043 } 00044 00045 00046 void RTC8564::setdaytime(char y[3], char m[3], char d[3], char h[3], char min[3], char s[3], char week_val[2]) 00047 { 00048 write(CONTROL1, 0x20); //stop 00049 write(CONTROL2, 0x00); 00050 write(YEARS, ((y[0]-0x30)<<4)+(y[1]-0x30)); 00051 write(MONTHS, ((m[0]-0x30)<<4)+(m[1]-0x30)); 00052 write(DAYS, ((d[0]-0x30)<<4)+(d[1]-0x30)); 00053 write(HOURS, ((h[0]-0x30)<<4)+(h[1]-0x30)); 00054 write(MINUTES, ((min[0]-0x30)<<4)+(min[1]-0x30)); 00055 write(SECONDS, ((s[0]-0x30)<<4)+(s[1]-0x30)); 00056 write(WEEKDAYS, week_val[0] - 0x30); //Sunday = "0", Monday = "1" ... 00057 write(CLOCKOUT_FREQ, 0x00); // 0x83 = TE on & 1Hz 00058 write(TIMER_CONTROL, 0x00); 00059 write(CONTROL1, 0x00); //start 00060 return; 00061 }
Generated on Tue Jul 19 2022 06:41:34 by
1.7.2