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