![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
Tarea sobre el reloj con alarma.
Dependencies: Debounced RTC-DS1307 TextLCD mbed
Fork of Rtc_Ds1307_lcd_alarma by
main.cpp@1:6dbe51fe0737, 2013-06-05 (annotated)
- Committer:
- leihen
- Date:
- Wed Jun 05 20:43:13 2013 +0000
- Revision:
- 1:6dbe51fe0737
- Parent:
- 0:431183c5b136
- Child:
- 2:3be003301107
Fully working sample to demonstrate the functionality of DS1307 library.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
leihen | 0:431183c5b136 | 1 | #include "mbed.h" |
leihen | 0:431183c5b136 | 2 | #include "Rtc_Ds1307.h" |
leihen | 0:431183c5b136 | 3 | |
leihen | 1:6dbe51fe0737 | 4 | Rtc_Ds1307 rtc(p9, p10); |
leihen | 0:431183c5b136 | 5 | |
leihen | 0:431183c5b136 | 6 | Serial pc(USBTX, USBRX, "pc"); |
leihen | 0:431183c5b136 | 7 | |
leihen | 0:431183c5b136 | 8 | char buffer[128]; |
leihen | 0:431183c5b136 | 9 | int readptr = 0; |
leihen | 1:6dbe51fe0737 | 10 | |
leihen | 0:431183c5b136 | 11 | int main() { |
leihen | 0:431183c5b136 | 12 | char c; |
leihen | 0:431183c5b136 | 13 | Time tm = {}; |
leihen | 0:431183c5b136 | 14 | |
leihen | 0:431183c5b136 | 15 | while(1) { |
leihen | 0:431183c5b136 | 16 | pc.printf("*************************************\n"); |
leihen | 0:431183c5b136 | 17 | pc.printf("* Menu for RTC Test : *\n"); |
leihen | 0:431183c5b136 | 18 | pc.printf("* read - reads the clock *\n"); |
leihen | 0:431183c5b136 | 19 | pc.printf("* start - start the clock *\n"); |
leihen | 0:431183c5b136 | 20 | pc.printf("* stop - stop the clock *\n"); |
leihen | 1:6dbe51fe0737 | 21 | pc.printf("* write - write the clock *\n"); |
leihen | 1:6dbe51fe0737 | 22 | pc.printf("* ena - enable Square wave output *\n"); |
leihen | 1:6dbe51fe0737 | 23 | pc.printf("* dis - disable square wave outp. *\n"); |
leihen | 0:431183c5b136 | 24 | pc.printf("*************************************\n"); |
leihen | 0:431183c5b136 | 25 | |
leihen | 0:431183c5b136 | 26 | while( (c = pc.getc()) != '\n') { |
leihen | 0:431183c5b136 | 27 | buffer[readptr++] = c; |
leihen | 0:431183c5b136 | 28 | } |
leihen | 0:431183c5b136 | 29 | buffer[readptr++] = 0; |
leihen | 0:431183c5b136 | 30 | if (strncmp(buffer, "read", 4) == 0) { |
leihen | 0:431183c5b136 | 31 | // perform read |
leihen | 0:431183c5b136 | 32 | pc.printf("Performing read operation\n"); |
leihen | 0:431183c5b136 | 33 | if (rtc.getTime(tm) ) { |
leihen | 0:431183c5b136 | 34 | pc.printf("The current time is : %02d:%02d:%02d\n", tm.hour, tm.min, tm.sec); |
leihen | 1:6dbe51fe0737 | 35 | pc.printf("The current date is : %s, %02d/%02d/%04d\n", rtc.weekdayToString(tm.wday), tm.mon, tm.date, tm.year); |
leihen | 0:431183c5b136 | 36 | } |
leihen | 0:431183c5b136 | 37 | |
leihen | 0:431183c5b136 | 38 | } |
leihen | 0:431183c5b136 | 39 | else if (strncmp(buffer, "write", 5) == 0) { |
leihen | 0:431183c5b136 | 40 | // perform write |
leihen | 1:6dbe51fe0737 | 41 | pc.printf("Enter the date (date 0..31)"); |
leihen | 1:6dbe51fe0737 | 42 | pc.scanf("%d", &tm.date); |
leihen | 1:6dbe51fe0737 | 43 | pc.printf("Enter the date (month 1..12)"); |
leihen | 1:6dbe51fe0737 | 44 | pc.scanf("%d", &tm.mon); |
leihen | 1:6dbe51fe0737 | 45 | pc.printf("Enter the date (year)"); |
leihen | 1:6dbe51fe0737 | 46 | pc.scanf("%d", &tm.year); |
leihen | 1:6dbe51fe0737 | 47 | pc.printf("Enter the time (hours 0..23)"); |
leihen | 1:6dbe51fe0737 | 48 | pc.scanf("%d", &tm.hour); |
leihen | 1:6dbe51fe0737 | 49 | pc.printf("Enter the time (minutes 0..59)"); |
leihen | 1:6dbe51fe0737 | 50 | pc.scanf("%d", &tm.min); |
leihen | 1:6dbe51fe0737 | 51 | pc.printf("Enter the time (seconds 0..59)"); |
leihen | 1:6dbe51fe0737 | 52 | pc.scanf("%d", &tm.sec); |
leihen | 0:431183c5b136 | 53 | pc.printf("Performing write operation\n"); |
leihen | 1:6dbe51fe0737 | 54 | |
leihen | 1:6dbe51fe0737 | 55 | while(pc.readable()) |
leihen | 1:6dbe51fe0737 | 56 | pc.getc(); |
leihen | 1:6dbe51fe0737 | 57 | rtc.setTime(tm, false, false); |
leihen | 0:431183c5b136 | 58 | } |
leihen | 0:431183c5b136 | 59 | else if (strncmp(buffer, "start", 5) == 0) { |
leihen | 0:431183c5b136 | 60 | // start |
leihen | 0:431183c5b136 | 61 | pc.printf("Performing start operation\n"); |
leihen | 1:6dbe51fe0737 | 62 | rtc.startClock(); |
leihen | 0:431183c5b136 | 63 | } |
leihen | 0:431183c5b136 | 64 | else if (strncmp(buffer, "stop", 4) == 0) { |
leihen | 0:431183c5b136 | 65 | // stop |
leihen | 0:431183c5b136 | 66 | pc.printf("Performing stop operation\n"); |
leihen | 1:6dbe51fe0737 | 67 | rtc.stopClock(); |
leihen | 1:6dbe51fe0737 | 68 | } |
leihen | 1:6dbe51fe0737 | 69 | else if (strncmp(buffer, "ena", 3) == 0) { |
leihen | 1:6dbe51fe0737 | 70 | int rs; |
leihen | 1:6dbe51fe0737 | 71 | pc.printf("Please specify the frequency : [0 = 1Hz, 1 = 4.096kHz, 2 = 8.192kHz, 3 = 32.768kHz] "); |
leihen | 1:6dbe51fe0737 | 72 | scanf("%d", &rs); |
leihen | 1:6dbe51fe0737 | 73 | pc.printf("Enabling the output with %d option\n", rs); |
leihen | 1:6dbe51fe0737 | 74 | rtc.setSquareWaveOutput(true, (RateSelect_t)rs); |
leihen | 1:6dbe51fe0737 | 75 | } |
leihen | 1:6dbe51fe0737 | 76 | else if (strncmp(buffer, "dis", 3) == 0) { |
leihen | 1:6dbe51fe0737 | 77 | pc.printf("Disableing square wave output\n"); |
leihen | 1:6dbe51fe0737 | 78 | rtc.setSquareWaveOutput(false, RS_1Hz); |
leihen | 0:431183c5b136 | 79 | } |
leihen | 0:431183c5b136 | 80 | else { |
leihen | 0:431183c5b136 | 81 | pc.printf("syntax error\n"); |
leihen | 0:431183c5b136 | 82 | } |
leihen | 0:431183c5b136 | 83 | readptr = 0; |
leihen | 0:431183c5b136 | 84 | pc.printf("\n\n\n"); |
leihen | 0:431183c5b136 | 85 | } |
leihen | 0:431183c5b136 | 86 | } |