Gustavo Ramirez
/
Rtc_Ds1307_Sample13
EJEMPLO PARA LA TAREA PICO Y PLACA
Fork of Rtc_Ds1307_Sample by
Embed:
(wiki syntax)
Show/hide line numbers
main.cpp
00001 #include "mbed.h" 00002 #include "Rtc_Ds1307.h" 00003 00004 //RtcCls rtc(p28, p27, p29, true); 00005 Rtc_Ds1307 rtc(PTE0,PTE1);//sda,scl 00006 00007 Serial pc(USBTX, USBRX, "pc"); 00008 00009 char buffer[128]; 00010 int readptr = 0; 00011 00012 int main() { 00013 char c; 00014 Rtc_Ds1307::Time_rtc tm = {}; 00015 00016 while(1) { 00017 pc.printf("*************************************\n"); 00018 pc.printf("* Menu for RTC Test : *\n"); 00019 pc.printf("* read - reads the clock *\n"); 00020 pc.printf("* start - start the clock *\n"); 00021 pc.printf("* stop - stop the clock *\n"); 00022 pc.printf("* write - write the clock *\n"); 00023 pc.printf("* ena - enable Square wave output *\n"); 00024 pc.printf("* dis - disable square wave outp. *\n"); 00025 pc.printf("*************************************\n"); 00026 00027 while( (c = pc.getc()) != '\n') { 00028 buffer[readptr++] = c; 00029 } 00030 buffer[readptr++] = 0; 00031 if (strncmp(buffer, "read", 4) == 0) { 00032 // perform read 00033 pc.printf("Performing read operation\n"); 00034 if (rtc.getTime(tm) ) { 00035 pc.printf("The current time is : %02d:%02d:%02d\n", tm.hour, tm.min, tm.sec); 00036 pc.printf("The current date is : %s, %02d/%02d/%04d\n", rtc.weekdayToString(tm.wday), tm.mon, tm.date, tm.year); 00037 } 00038 00039 } 00040 else if (strncmp(buffer, "write", 5) == 0) { 00041 // perform write 00042 pc.printf("Enter the date (date 0..31)"); 00043 pc.scanf("%d", &tm.date); 00044 pc.printf("Enter the date (month 1..12)"); 00045 pc.scanf("%d", &tm.mon); 00046 pc.printf("Enter the date (year)"); 00047 pc.scanf("%d", &tm.year); 00048 pc.printf("Enter the time (hours 0..23)"); 00049 pc.scanf("%d", &tm.hour); 00050 pc.printf("Enter the time (minutes 0..59)"); 00051 pc.scanf("%d", &tm.min); 00052 pc.printf("Enter the time (seconds 0..59)"); 00053 pc.scanf("%d", &tm.sec); 00054 pc.printf("Performing write operation\n"); 00055 00056 while(pc.readable()) 00057 pc.getc(); 00058 rtc.setTime(tm, false, false); 00059 } 00060 else if (strncmp(buffer, "start", 5) == 0) { 00061 // start 00062 pc.printf("Performing start operation\n"); 00063 rtc.startClock(); 00064 } 00065 else if (strncmp(buffer, "stop", 4) == 0) { 00066 // stop 00067 pc.printf("Performing stop operation\n"); 00068 rtc.stopClock(); 00069 } 00070 else if (strncmp(buffer, "ena", 3) == 0) { 00071 int rs; 00072 pc.printf("Please specify the frequency : [0 = 1Hz, 1 = 4.096kHz, 2 = 8.192kHz, 3 = 32.768kHz] "); 00073 scanf("%d", &rs); 00074 pc.printf("Enabling the output with %d option\n", rs); 00075 rtc.setSquareWaveOutput(true, (Rtc_Ds1307::SqwRateSelect_t)rs); 00076 } 00077 else if (strncmp(buffer, "dis", 3) == 0) { 00078 pc.printf("Disableing square wave output\n"); 00079 rtc.setSquareWaveOutput(false, Rtc_Ds1307::RS1Hz); 00080 } 00081 else { 00082 pc.printf("syntax error\n"); 00083 } 00084 readptr = 0; 00085 pc.printf("\n\n\n"); 00086 } 00087 }
Generated on Sun Jul 24 2022 12:46:12 by 1.7.2