MANOJ NARAYANAN
/
RTC_Sample_manoj
Sample program RTC DS1307
Fork of Rtc_Ds1307_Sample by
main.cpp@0:431183c5b136, 2013-06-02 (annotated)
- Committer:
- leihen
- Date:
- Sun Jun 02 18:57:52 2013 +0000
- Revision:
- 0:431183c5b136
- Child:
- 1:6dbe51fe0737
First complete Version. Untested.
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 | 0:431183c5b136 | 4 | DigitalOut myled(LED1); |
leihen | 0:431183c5b136 | 5 | |
leihen | 0:431183c5b136 | 6 | Rtc_Ds1307 rtc(p28, p27); |
leihen | 0:431183c5b136 | 7 | |
leihen | 0:431183c5b136 | 8 | Serial pc(USBTX, USBRX, "pc"); |
leihen | 0:431183c5b136 | 9 | |
leihen | 0:431183c5b136 | 10 | char buffer[128]; |
leihen | 0:431183c5b136 | 11 | int readptr = 0; |
leihen | 0:431183c5b136 | 12 | int main() { |
leihen | 0:431183c5b136 | 13 | char c; |
leihen | 0:431183c5b136 | 14 | pc.printf("Good morning Henry\n"); |
leihen | 0:431183c5b136 | 15 | Time tm = {}; |
leihen | 0:431183c5b136 | 16 | |
leihen | 0:431183c5b136 | 17 | while(1) { |
leihen | 0:431183c5b136 | 18 | pc.printf("*************************************\n"); |
leihen | 0:431183c5b136 | 19 | pc.printf("* Menu for RTC Test : *\n"); |
leihen | 0:431183c5b136 | 20 | pc.printf("* read - reads the clock *\n"); |
leihen | 0:431183c5b136 | 21 | pc.printf("* start - start the clock *\n"); |
leihen | 0:431183c5b136 | 22 | pc.printf("* stop - stop the clock *\n"); |
leihen | 0:431183c5b136 | 23 | pc.printf(" write - write the clock *\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 | 0:431183c5b136 | 35 | } |
leihen | 0:431183c5b136 | 36 | |
leihen | 0:431183c5b136 | 37 | } |
leihen | 0:431183c5b136 | 38 | else if (strncmp(buffer, "write", 5) == 0) { |
leihen | 0:431183c5b136 | 39 | // perform write |
leihen | 0:431183c5b136 | 40 | pc.printf("Performing write operation\n"); |
leihen | 0:431183c5b136 | 41 | } |
leihen | 0:431183c5b136 | 42 | else if (strncmp(buffer, "start", 5) == 0) { |
leihen | 0:431183c5b136 | 43 | // start |
leihen | 0:431183c5b136 | 44 | pc.printf("Performing start operation\n"); |
leihen | 0:431183c5b136 | 45 | } |
leihen | 0:431183c5b136 | 46 | else if (strncmp(buffer, "stop", 4) == 0) { |
leihen | 0:431183c5b136 | 47 | // stop |
leihen | 0:431183c5b136 | 48 | pc.printf("Performing stop operation\n"); |
leihen | 0:431183c5b136 | 49 | } |
leihen | 0:431183c5b136 | 50 | else { |
leihen | 0:431183c5b136 | 51 | pc.printf("syntax error\n"); |
leihen | 0:431183c5b136 | 52 | } |
leihen | 0:431183c5b136 | 53 | readptr = 0; |
leihen | 0:431183c5b136 | 54 | pc.printf("\n\n\n"); |
leihen | 0:431183c5b136 | 55 | } |
leihen | 0:431183c5b136 | 56 | } |