pour olivier

Dependencies:   RTC-DS1307 mbed

Fork of Rtc_Ds1307_Sample by Henry Leinen

Committer:
mathieusab
Date:
Fri Dec 09 16:50:57 2016 +0000
Revision:
3:79b8df1189ea
Parent:
2:3be003301107
pour olivier

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