pour olivier

Dependencies:   RTC-DS1307 mbed

Fork of Rtc_Ds1307_Sample by Henry Leinen

Committer:
leihen
Date:
Wed Jun 26 21:07:13 2013 +0000
Revision:
2:3be003301107
Parent:
1:6dbe51fe0737
Child:
3:79b8df1189ea
Updated library

Who changed what in which revision?

UserRevisionLine numberNew contents of line
leihen 0:431183c5b136 1 #include "mbed.h"
leihen 0:431183c5b136 2 #include "Rtc_Ds1307.h"
leihen 0:431183c5b136 3
leihen 2:3be003301107 4 //RtcCls rtc(p28, p27, p29, true);
leihen 2:3be003301107 5 Rtc_Ds1307 rtc(p28, p27);
leihen 0:431183c5b136 6
leihen 0:431183c5b136 7 Serial pc(USBTX, USBRX, "pc");
leihen 0:431183c5b136 8
leihen 0:431183c5b136 9 char buffer[128];
leihen 0:431183c5b136 10 int readptr = 0;
leihen 1:6dbe51fe0737 11
leihen 0:431183c5b136 12 int main() {
leihen 0:431183c5b136 13 char c;
leihen 2:3be003301107 14 Rtc_Ds1307::Time_rtc tm = {};
leihen 0:431183c5b136 15
leihen 0:431183c5b136 16 while(1) {
leihen 0:431183c5b136 17 pc.printf("*************************************\n");
leihen 0:431183c5b136 18 pc.printf("* Menu for RTC Test : *\n");
leihen 0:431183c5b136 19 pc.printf("* read - reads the clock *\n");
leihen 0:431183c5b136 20 pc.printf("* start - start the clock *\n");
leihen 0:431183c5b136 21 pc.printf("* stop - stop the clock *\n");
leihen 1:6dbe51fe0737 22 pc.printf("* write - write the clock *\n");
leihen 1:6dbe51fe0737 23 pc.printf("* ena - enable Square wave output *\n");
leihen 1:6dbe51fe0737 24 pc.printf("* dis - disable square wave outp. *\n");
leihen 0:431183c5b136 25 pc.printf("*************************************\n");
leihen 0:431183c5b136 26
leihen 0:431183c5b136 27 while( (c = pc.getc()) != '\n') {
leihen 0:431183c5b136 28 buffer[readptr++] = c;
leihen 0:431183c5b136 29 }
leihen 0:431183c5b136 30 buffer[readptr++] = 0;
leihen 0:431183c5b136 31 if (strncmp(buffer, "read", 4) == 0) {
leihen 0:431183c5b136 32 // perform read
leihen 0:431183c5b136 33 pc.printf("Performing read operation\n");
leihen 0:431183c5b136 34 if (rtc.getTime(tm) ) {
leihen 0:431183c5b136 35 pc.printf("The current time is : %02d:%02d:%02d\n", tm.hour, tm.min, tm.sec);
leihen 1:6dbe51fe0737 36 pc.printf("The current date is : %s, %02d/%02d/%04d\n", rtc.weekdayToString(tm.wday), tm.mon, tm.date, tm.year);
leihen 0:431183c5b136 37 }
leihen 0:431183c5b136 38
leihen 0:431183c5b136 39 }
leihen 0:431183c5b136 40 else if (strncmp(buffer, "write", 5) == 0) {
leihen 0:431183c5b136 41 // perform write
leihen 1:6dbe51fe0737 42 pc.printf("Enter the date (date 0..31)");
leihen 1:6dbe51fe0737 43 pc.scanf("%d", &tm.date);
leihen 1:6dbe51fe0737 44 pc.printf("Enter the date (month 1..12)");
leihen 1:6dbe51fe0737 45 pc.scanf("%d", &tm.mon);
leihen 1:6dbe51fe0737 46 pc.printf("Enter the date (year)");
leihen 1:6dbe51fe0737 47 pc.scanf("%d", &tm.year);
leihen 1:6dbe51fe0737 48 pc.printf("Enter the time (hours 0..23)");
leihen 1:6dbe51fe0737 49 pc.scanf("%d", &tm.hour);
leihen 1:6dbe51fe0737 50 pc.printf("Enter the time (minutes 0..59)");
leihen 1:6dbe51fe0737 51 pc.scanf("%d", &tm.min);
leihen 1:6dbe51fe0737 52 pc.printf("Enter the time (seconds 0..59)");
leihen 1:6dbe51fe0737 53 pc.scanf("%d", &tm.sec);
leihen 0:431183c5b136 54 pc.printf("Performing write operation\n");
leihen 1:6dbe51fe0737 55
leihen 1:6dbe51fe0737 56 while(pc.readable())
leihen 1:6dbe51fe0737 57 pc.getc();
leihen 1:6dbe51fe0737 58 rtc.setTime(tm, false, false);
leihen 0:431183c5b136 59 }
leihen 0:431183c5b136 60 else if (strncmp(buffer, "start", 5) == 0) {
leihen 0:431183c5b136 61 // start
leihen 0:431183c5b136 62 pc.printf("Performing start operation\n");
leihen 1:6dbe51fe0737 63 rtc.startClock();
leihen 0:431183c5b136 64 }
leihen 0:431183c5b136 65 else if (strncmp(buffer, "stop", 4) == 0) {
leihen 0:431183c5b136 66 // stop
leihen 0:431183c5b136 67 pc.printf("Performing stop operation\n");
leihen 1:6dbe51fe0737 68 rtc.stopClock();
leihen 1:6dbe51fe0737 69 }
leihen 1:6dbe51fe0737 70 else if (strncmp(buffer, "ena", 3) == 0) {
leihen 1:6dbe51fe0737 71 int rs;
leihen 1:6dbe51fe0737 72 pc.printf("Please specify the frequency : [0 = 1Hz, 1 = 4.096kHz, 2 = 8.192kHz, 3 = 32.768kHz] ");
leihen 1:6dbe51fe0737 73 scanf("%d", &rs);
leihen 1:6dbe51fe0737 74 pc.printf("Enabling the output with %d option\n", rs);
leihen 2:3be003301107 75 rtc.setSquareWaveOutput(true, (Rtc_Ds1307::SqwRateSelect_t)rs);
leihen 1:6dbe51fe0737 76 }
leihen 1:6dbe51fe0737 77 else if (strncmp(buffer, "dis", 3) == 0) {
leihen 1:6dbe51fe0737 78 pc.printf("Disableing square wave output\n");
leihen 2:3be003301107 79 rtc.setSquareWaveOutput(false, Rtc_Ds1307::RS1Hz);
leihen 0:431183c5b136 80 }
leihen 0:431183c5b136 81 else {
leihen 0:431183c5b136 82 pc.printf("syntax error\n");
leihen 0:431183c5b136 83 }
leihen 0:431183c5b136 84 readptr = 0;
leihen 0:431183c5b136 85 pc.printf("\n\n\n");
leihen 0:431183c5b136 86 }
leihen 0:431183c5b136 87 }