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