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 Oxford CWM Team

Committer:
mlin
Date:
Thu May 25 15:32:20 2017 +0000
Revision:
31:3255668e6b08
Parent:
16:3cb9b1fbc039
Child:
38:3fe3bafbf0c7
.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mlin 11:1da15361a35b 1 #include "Rtc_Ds1307.h"
mlin 9:eee503060d69 2 Rtc_Ds1307 rtc(I2C_SDA, I2C_SCL);
mlin 9:eee503060d69 3 Rtc_Ds1307::Time_rtc tm_c = {};
mlin 16:3cb9b1fbc039 4 int tm_a_hr, tm_a_min = 0;
mlin 9:eee503060d69 5 char buffer[128];
mlin 9:eee503060d69 6 int readptr = 0;
mlin 9:eee503060d69 7
mlin 9:eee503060d69 8
mlin 11:1da15361a35b 9 void read_time()
mlin 11:1da15361a35b 10 {
mlin 11:1da15361a35b 11 // perform read
mlin 9:eee503060d69 12 int n = 0;
mlin 9:eee503060d69 13 do {
mlin 9:eee503060d69 14 n++;
mlin 9:eee503060d69 15 } while(!rtc.getTime(tm_c));
mlin 31:3255668e6b08 16
mlin 9:eee503060d69 17 }
mlin 9:eee503060d69 18
mlin 11:1da15361a35b 19 void write()
mlin 11:1da15361a35b 20 {
mlin 9:eee503060d69 21 // perform write
mlin 9:eee503060d69 22 pc.printf("Enter the date (date 0..31)");
mlin 9:eee503060d69 23 pc.scanf("%d", &tm_c.date);
mlin 9:eee503060d69 24 pc.printf("Enter the date (month 1..12)");
mlin 9:eee503060d69 25 pc.scanf("%d", &tm_c.mon);
mlin 9:eee503060d69 26 pc.printf("Enter the date (year)");
mlin 9:eee503060d69 27 pc.scanf("%d", &tm_c.year);
mlin 9:eee503060d69 28 pc.printf("Enter the time (hours 0..23)");
mlin 9:eee503060d69 29 pc.scanf("%d", &tm_c.hour);
mlin 9:eee503060d69 30 pc.printf("Enter the time (minutes 0..59)");
mlin 9:eee503060d69 31 pc.scanf("%d", &tm_c.min);
mlin 9:eee503060d69 32 pc.printf("Enter the time (seconds 0..59)");
mlin 9:eee503060d69 33 pc.scanf("%d", &tm_c.sec);
mlin 9:eee503060d69 34 pc.printf("Performing write operation\n\r");
mlin 11:1da15361a35b 35
mlin 11:1da15361a35b 36 while(pc.readable())
mlin 11:1da15361a35b 37
mlin 9:eee503060d69 38 pc.getc();
mlin 9:eee503060d69 39 int n = 0;
mlin 11:1da15361a35b 40 while (!rtc.setTime(tm_c, true, false)) { //set the Time in RTC Param : ( Time container, Start Clock, Twelve Hour Clock)
mlin 11:1da15361a35b 41 n++;
mlin 9:eee503060d69 42 }
mlin 11:1da15361a35b 43 pc.printf("Tried to write %d times\n\r",n);
mlin 9:eee503060d69 44 }
mlin 9:eee503060d69 45
mlin 9:eee503060d69 46 //other RTC functions:
mlin 9:eee503060d69 47 //rtc.startClock();
mlin 9:eee503060d69 48 //rtc.stopClock();
mlin 9:eee503060d69 49 //square wave
mlin 9:eee503060d69 50 // int rs;
mlin 9:eee503060d69 51 // pc.printf("Please specify the frequency : [0 = 1Hz, 1 = 4.096kHz, 2 = 8.192kHz, 3 = 32.768kHz] ");
mlin 9:eee503060d69 52 // scanf("%d", &rs);
mlin 9:eee503060d69 53 // pc.printf("Enabling the output with %d option\n", rs);
mlin 9:eee503060d69 54 // rtc.setSquareWaveOutput(true, (Rtc_Ds1307::SqwRateSelect_t)rs);
mlin 9:eee503060d69 55
mlin 9:eee503060d69 56
mlin 9:eee503060d69 57 //square wave off
mlin 9:eee503060d69 58 //rtc.setSquareWaveOutput(false, Rtc_Ds1307::RS1Hz);