Contains the main execution of the clock uses headers to import functions
Dependencies: RTC-DS1307 SPI_TFT_ILI9341 TFT_fonts mbed tsi_sensor
Fork of TFT_Mikroelectronika_IL9341_sketchpad by
RTC.h
- Committer:
- Owenmatthewmcgowan
- Date:
- 2017-05-26
- Revision:
- 49:243b5e826228
- Parent:
- 38:3fe3bafbf0c7
File content as of revision 49:243b5e826228:
#include "Rtc_Ds1307.h" #include "math.h" Rtc_Ds1307 rtc(I2C_SDA, I2C_SCL); Rtc_Ds1307::Time_rtc tm_c = {}; int tm_a_hr, tm_a_min = 0; char buffer[128]; int readptr = 0; int date2day(int date,int month,int year){ int m = ((((month + 9) % 12 + 1) * 2.6) - 0.2); int c = year / 100; int y = year % 100; int w = (date + m - 2 * c + y + y / 4 + (c / 4)) % 7; return w; } void read_time() { // perform read int n = 0; do { n++; } while(!rtc.getTime(tm_c)); tm_c.wday = date2day(tm_c.date, tm_c.mon, tm_c.year); } void write() { // perform write pc.printf("Enter the date (date 0..31)"); pc.scanf("%d", &tm_c.date); pc.printf("Enter the date (month 1..12)"); pc.scanf("%d", &tm_c.mon); pc.printf("Enter the date (year)"); pc.scanf("%d", &tm_c.year); pc.printf("Enter the time (hours 0..23)"); pc.scanf("%d", &tm_c.hour); pc.printf("Enter the time (minutes 0..59)"); pc.scanf("%d", &tm_c.min); pc.printf("Enter the time (seconds 0..59)"); pc.scanf("%d", &tm_c.sec); pc.printf("Performing write operation\n\r"); while(pc.readable()) pc.getc(); int n = 0; while (!rtc.setTime(tm_c, true, false)) { //set the Time in RTC Param : ( Time container, Start Clock, Twelve Hour Clock) n++; } pc.printf("Tried to write %d times\n\r",n); } //other RTC functions: //rtc.startClock(); //rtc.stopClock(); //square wave // int rs; // pc.printf("Please specify the frequency : [0 = 1Hz, 1 = 4.096kHz, 2 = 8.192kHz, 3 = 32.768kHz] "); // scanf("%d", &rs); // pc.printf("Enabling the output with %d option\n", rs); // rtc.setSquareWaveOutput(true, (Rtc_Ds1307::SqwRateSelect_t)rs); //square wave off //rtc.setSquareWaveOutput(false, Rtc_Ds1307::RS1Hz);