![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
hi
Dependencies: mbed TM1636 RTC-DS1307
Diff: main.cpp
- Revision:
- 3:3d8968877eee
- Parent:
- 2:3be003301107
- Child:
- 4:051852f988eb
--- a/main.cpp Wed Jun 26 21:07:13 2013 +0000 +++ b/main.cpp Mon Dec 17 06:40:00 2018 +0000 @@ -2,86 +2,33 @@ #include "Rtc_Ds1307.h" //RtcCls rtc(p28, p27, p29, true); -Rtc_Ds1307 rtc(p28, p27); - +Rtc_Ds1307 rtc(D14, D15); +DigitalIn button_K1(A5); Serial pc(USBTX, USBRX, "pc"); char buffer[128]; int readptr = 0; int main() { - char c; + button_K1.mode(PullUp); Rtc_Ds1307::Time_rtc tm = {}; - + tm.date = 1 ; + tm.mon = 1 ; + tm.year = 12 ; + tm.hour = 0; + tm.min = 0; + tm.sec = 0; + rtc.setTime(tm, false, false); + rtc.startClock(); while(1) { - pc.printf("*************************************\n"); - pc.printf("* Menu for RTC Test : *\n"); - pc.printf("* read - reads the clock *\n"); - pc.printf("* start - start the clock *\n"); - pc.printf("* stop - stop the clock *\n"); - pc.printf("* write - write the clock *\n"); - pc.printf("* ena - enable Square wave output *\n"); - pc.printf("* dis - disable square wave outp. *\n"); - pc.printf("*************************************\n"); - - while( (c = pc.getc()) != '\n') { - buffer[readptr++] = c; - } - buffer[readptr++] = 0; - if (strncmp(buffer, "read", 4) == 0) { - // perform read - pc.printf("Performing read operation\n"); - if (rtc.getTime(tm) ) { - pc.printf("The current time is : %02d:%02d:%02d\n", tm.hour, tm.min, tm.sec); - pc.printf("The current date is : %s, %02d/%02d/%04d\n", rtc.weekdayToString(tm.wday), tm.mon, tm.date, tm.year); - } + if(!button_K1){ + rtc.getTime(tm); + pc.printf("%02d:%02d:%02d\n",tm.hour,tm.min,tm.sec); + wait(0.3); + } + - } - else if (strncmp(buffer, "write", 5) == 0) { - // perform write - pc.printf("Enter the date (date 0..31)"); - pc.scanf("%d", &tm.date); - pc.printf("Enter the date (month 1..12)"); - pc.scanf("%d", &tm.mon); - pc.printf("Enter the date (year)"); - pc.scanf("%d", &tm.year); - pc.printf("Enter the time (hours 0..23)"); - pc.scanf("%d", &tm.hour); - pc.printf("Enter the time (minutes 0..59)"); - pc.scanf("%d", &tm.min); - pc.printf("Enter the time (seconds 0..59)"); - pc.scanf("%d", &tm.sec); - pc.printf("Performing write operation\n"); - - while(pc.readable()) - pc.getc(); - rtc.setTime(tm, false, false); - } - else if (strncmp(buffer, "start", 5) == 0) { - // start - pc.printf("Performing start operation\n"); - rtc.startClock(); - } - else if (strncmp(buffer, "stop", 4) == 0) { - // stop - pc.printf("Performing stop operation\n"); - rtc.stopClock(); - } - else if (strncmp(buffer, "ena", 3) == 0) { - 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); - } - else if (strncmp(buffer, "dis", 3) == 0) { - pc.printf("Disableing square wave output\n"); - rtc.setSquareWaveOutput(false, Rtc_Ds1307::RS1Hz); - } - else { - pc.printf("syntax error\n"); - } - readptr = 0; - pc.printf("\n\n\n"); - } -} + //rtc.stopClock(); + } + } + \ No newline at end of file