Fork of Demo program for ard2pmod library. Alarm features of RTC have not been tested, please try them out.
Dependencies: Terminal ard2pmod mbed
Fork of ard2pmod_demo by
Revision 14:08a83dc0e58e, committed 2016-03-29
- Comitter:
- j3
- Date:
- Tue Mar 29 01:23:35 2016 +0000
- Parent:
- 13:067920a73c78
- Commit message:
- updated libraries
Changed in this revision
diff -r 067920a73c78 -r 08a83dc0e58e Terminal.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Terminal.lib Tue Mar 29 01:23:35 2016 +0000 @@ -0,0 +1,1 @@ +https://developer.mbed.org/users/j3/code/Terminal/#7c269f52ad77
diff -r 067920a73c78 -r 08a83dc0e58e ard2pmod.lib --- a/ard2pmod.lib Thu Mar 19 23:53:08 2015 +0000 +++ b/ard2pmod.lib Tue Mar 29 01:23:35 2016 +0000 @@ -1,1 +1,1 @@ -http://developer.mbed.org/teams/Maxim-Integrated/code/ard2pmod/#abb327ca5580 +https://developer.mbed.org/users/j3/code/ard2pmod/#294c52822d28
diff -r 067920a73c78 -r 08a83dc0e58e main.cpp --- a/main.cpp Thu Mar 19 23:53:08 2015 +0000 +++ b/main.cpp Tue Mar 29 01:23:35 2016 +0000 @@ -42,14 +42,11 @@ **********************************************************************/ +#include "Terminal.h" #include "ard2pmod.h" - -#define ESC 0x1B +#include "ds3231.h" -void get_user_input(char* message, uint8_t min, uint8_t max, uint32_t* member); -void get_user_input(char* message, uint8_t min, uint8_t max, bool* member); -Serial term(USBTX, USBRX); int main(void) { @@ -66,14 +63,11 @@ PMOD_TYPE_6_HBRIDGE */ - Ard2Pmod rtc(Ard2Pmod::PMOD_TYPE_1_GPIO); - - //default destructor call example - //rtc.~Ard2Pmod(); + Terminal term(USBTX, USBRX); - //can be used to wiggle lines for PMOD_TYPE_1_GPIO - //BusOut pmod_A(D10, D11, D12, D13); - //BusOut pmod_B(D4, D5, D6, D7); + Ard2Pmod board(Ard2Pmod::PMOD_TYPE_1_GPIO); + + Ds3231 rtc(D14, D15); //DS3231 rtc variables //default for control and status registers, @@ -82,74 +76,72 @@ ds3231_time_t rtc_time; ds3231_calendar_t rtc_calendar; - time_t epoch_time; - rtc.set_cntl_stat_reg(rtc_control_status); uint32_t user_input; - get_user_input("\nDo you want to set the RTC time and calendar (1 for yes, 0 for no): ", 0, - 1, &user_input); + user_input = term.get_int32("\nDo you want to set the RTC time and calendar (1 for yes, 0 for no): \n", 0, 1); if(user_input) { //get day from user - get_user_input("\nPlease enter day of week, 1 for Sunday (1-7): ", 1, - 7, &rtc_calendar.day); + rtc_calendar.day = term.get_int32("\nPlease enter day of week, 1 for Sunday (1-7): ", 1, 7); //get day of month from user - get_user_input("\nPlease enter day of month (1-31): ", 1, 31, - &rtc_calendar.date); + rtc_calendar.date = term.get_int32("\nPlease enter day of month (1-31): ", 1, 31); //get month from user - get_user_input("\nPlease enter the month, 1 for January (1-12): ", 1, - 12, &rtc_calendar.month); - + rtc_calendar.month = term.get_int32("\nPlease enter the month, 1 for January (1-12): ", 1, 12); + //get year from user - get_user_input("\nPlease enter the year (0-99): ",0, 99, - &rtc_calendar.year); + rtc_calendar.year = term.get_int32("\nPlease enter the year (0-99): ", 0, 99); //Get time mode - get_user_input("\nWhat time mode? 1 for 12hr 0 for 24hr: ", 0, 1, - &rtc_time.mode); + rtc_time.mode = term.get_int32("\nWhat time mode? 1 for 12hr 0 for 24hr: ", 0, 1); if(rtc_time.mode) { //Get AM/PM status - get_user_input("\nIs it AM or PM? 0 for AM 1 for PM: ", 0, 1, - &rtc_time.am_pm); + rtc_time.am_pm = term.get_int32("\nIs it AM or PM? 0 for AM 1 for PM: ", 0, 1); + //Get hour from user - get_user_input("\nPlease enter the hour (1-12): ", 1, 12, - &rtc_time.hours); + rtc_time.hours = term.get_int32("\nPlease enter the hour (1-12): ", 1, 12); } else { //Get hour from user - get_user_input("\nPlease enter the hour (0-23): ", 0, 23, - &rtc_time.hours); + rtc_time.hours = term.get_int32("\nPlease enter the hour (0-23): ", 0, 23); } //Get minutes from user - get_user_input("\nPlease enter the minute (0-59): ", 0, 59, - &rtc_time.minutes); + rtc_time.minutes = term.get_int32("\nPlease enter the minute (0-59): ", 0, 59); + //Get seconds from user - get_user_input("\nPlease enter the second (0-59): ", 0, 59, - &rtc_time.seconds); + rtc_time.seconds = term.get_int32("\nPlease enter the second (0-59): ", 0, 59); - //Set the time - rtc.set_time(rtc_time); + //Set the time, uses inverted logic for return value + if(rtc.set_time(rtc_time)) + { + term.printf("\nrtc.set_time failed!!\n"); + while(1); + } - //Set the calendar - rtc.set_calendar(rtc_calendar); + //Set the calendar, uses inverted logic for return value + if(rtc.set_calendar(rtc_calendar)) + { + term.printf("\nrtc.set_calendar failed!!\n"); + while(1); + } } + time_t epoch_time; char buffer[32]; for(;;) - { - term.printf("%c[2J", ESC); //clear screen - term.printf("%c[H", ESC); //move cursor to Home + { + term.cls(); + term.locate(0,0); //move home //new epoch time fx epoch_time = rtc.get_epoch(); @@ -158,11 +150,11 @@ term.printf("\nTime as a basic string = %s", ctime(&epoch_time)); - strftime(buffer, 32, "%I:%M %p\n", localtime(&epoch_time)); + strftime(buffer, 32, "%I:%M %p", localtime(&epoch_time)); term.printf("\nTime as a custom formatted string = %s", buffer); - wait(1.0); - }//loop + wait_ms(1000); + } }
diff -r 067920a73c78 -r 08a83dc0e58e mbed.bld --- a/mbed.bld Thu Mar 19 23:53:08 2015 +0000 +++ b/mbed.bld Tue Mar 29 01:23:35 2016 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/mbed_official/code/mbed/builds/7e07b6fb45cf \ No newline at end of file +http://mbed.org/users/mbed_official/code/mbed/builds/7cff1c4259d7 \ No newline at end of file