Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: RTC-DS1307 TextLCD mbed
Fork of Rtc_Ds1307_Sample by
Revision 1:6dbe51fe0737, committed 2013-06-05
- Comitter:
- leihen
- Date:
- Wed Jun 05 20:43:13 2013 +0000
- Parent:
- 0:431183c5b136
- Child:
- 2:3be003301107
- Commit message:
- Fully working sample to demonstrate the functionality of DS1307 library.
Changed in this revision
| RTC-DS1307.lib | Show annotated file Show diff for this revision Revisions of this file |
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/RTC-DS1307.lib Sun Jun 02 18:57:52 2013 +0000 +++ b/RTC-DS1307.lib Wed Jun 05 20:43:13 2013 +0000 @@ -1,1 +1,1 @@ -https://mbed.org/users/leihen/code/RTC-DS1307/#64274190e842 +https://mbed.org/users/leihen/code/RTC-DS1307/#ee81f2c5a706
--- a/main.cpp Sun Jun 02 18:57:52 2013 +0000
+++ b/main.cpp Wed Jun 05 20:43:13 2013 +0000
@@ -1,17 +1,15 @@
#include "mbed.h"
#include "Rtc_Ds1307.h"
-DigitalOut myled(LED1);
-
-Rtc_Ds1307 rtc(p28, p27);
+Rtc_Ds1307 rtc(p9, p10);
Serial pc(USBTX, USBRX, "pc");
char buffer[128];
int readptr = 0;
+
int main() {
char c;
- pc.printf("Good morning Henry\n");
Time tm = {};
while(1) {
@@ -20,7 +18,9 @@
pc.printf("* read - reads the clock *\n");
pc.printf("* start - start the clock *\n");
pc.printf("* stop - stop the clock *\n");
- pc.printf(" write - write the clock *\n");
+ pc.printf("* write - write the clock *\n");
+ pc.printf("* ena - enable Square wave output *\n");
+ pc.printf("* dis - disable square wave outp. *\n");
pc.printf("*************************************\n");
while( (c = pc.getc()) != '\n') {
@@ -32,20 +32,50 @@
pc.printf("Performing read operation\n");
if (rtc.getTime(tm) ) {
pc.printf("The current time is : %02d:%02d:%02d\n", tm.hour, tm.min, tm.sec);
+ pc.printf("The current date is : %s, %02d/%02d/%04d\n", rtc.weekdayToString(tm.wday), tm.mon, tm.date, tm.year);
}
}
else if (strncmp(buffer, "write", 5) == 0) {
// perform write
+ pc.printf("Enter the date (date 0..31)");
+ pc.scanf("%d", &tm.date);
+ pc.printf("Enter the date (month 1..12)");
+ pc.scanf("%d", &tm.mon);
+ pc.printf("Enter the date (year)");
+ pc.scanf("%d", &tm.year);
+ pc.printf("Enter the time (hours 0..23)");
+ pc.scanf("%d", &tm.hour);
+ pc.printf("Enter the time (minutes 0..59)");
+ pc.scanf("%d", &tm.min);
+ pc.printf("Enter the time (seconds 0..59)");
+ pc.scanf("%d", &tm.sec);
pc.printf("Performing write operation\n");
+
+ while(pc.readable())
+ pc.getc();
+ rtc.setTime(tm, false, false);
}
else if (strncmp(buffer, "start", 5) == 0) {
// start
pc.printf("Performing start operation\n");
+ rtc.startClock();
}
else if (strncmp(buffer, "stop", 4) == 0) {
// stop
pc.printf("Performing stop operation\n");
+ rtc.stopClock();
+ }
+ else if (strncmp(buffer, "ena", 3) == 0) {
+ int rs;
+ pc.printf("Please specify the frequency : [0 = 1Hz, 1 = 4.096kHz, 2 = 8.192kHz, 3 = 32.768kHz] ");
+ scanf("%d", &rs);
+ pc.printf("Enabling the output with %d option\n", rs);
+ rtc.setSquareWaveOutput(true, (RateSelect_t)rs);
+ }
+ else if (strncmp(buffer, "dis", 3) == 0) {
+ pc.printf("Disableing square wave output\n");
+ rtc.setSquareWaveOutput(false, RS_1Hz);
}
else {
pc.printf("syntax error\n");
