DS2331 Real Time Clock
I²C-Integrated RTC/TCXO/Crystal
- Real-Time Clock Counts Seconds, Minutes, Hours, Date of the Month, Month, Day of the Week, and Year, with Leap-Year Compensation Valid Up to 2100
- Accuracy ±2ppm from 0°C to +40°C
- Accuracy ±3.5ppm from -40°C to +85°C
- Digital Temp Sensor Output: ±3°C Accuracy
- Register for Aging Trim
- Active-Low RST Output/Pushbutton Reset Debounce Input
- Two Time-of-Day Alarms
- Programmable Square-Wave Output Signal
- Simple Serial Interface Connects to Most Microcontrollers
- Fast (400kHz) I2C Interface
- Battery-Backup Input for Continuous Timekeeping
- Low Power Operation Extends Battery-Backup Run Time
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | //DS2331 Real Time Clock #include "RTClib.h" //https://github.com/adafruit/RTClib //MEGA2560 SDA/SCL ->20 & 21 RTC_DS3231 rtc; Void setup() { Serial.begin(9600); if (! rtc.begin()) { Serial.println("Couldn't find RTC"); } else { Serial.println("Fond RTC"); if (rtc.lostPower()) { Serial.println("RTC lost power, lets set the time!"); // following line sets the RTC to the date & time this sketch was compiled rtc.adjust(DateTime(F(__DATE__), F(__TIME__))); // This line sets the RTC with an explicit date & time, for example to set // January 21, 2014 at 3am you would call: // rtc.adjust(DateTime(2014, 1, 21, 3, 0, 0)); } } Void loop() { DateTime now = get_Time(); sprintf(char_buffer,"%d/%d/%d",now.year(),now.month(),now.day()); Serial.println(char_buffer); sprintf(char_buffer,"%d:%d:%d",now.hour(),now.minute(),now.second()); Serial.println(char_buffer); Delay (1000); } |