Giovani Cardona
/
4_1_DS3231demo
Ejemplo RTC DS3231
Diff: main.cpp
- Revision:
- 1:7db4a1cc7abb
- Parent:
- 0:6be499dd402a
- Child:
- 2:76cd47a603b5
--- a/main.cpp Wed Nov 19 04:16:48 2014 +0000 +++ b/main.cpp Thu Nov 20 00:04:13 2014 +0000 @@ -2,15 +2,87 @@ #include "ds3231.h" +void get_user_input(char* message, uint8_t min, uint8_t max, uint8_t* member); + +Serial term(USBTX, USBRX); int main(void) { - //instantiate rtc object + //rtc object Ds3231 rtc(D14, D15); - for(;;) + //DS3231 rtc variables + ds3231_cntl_stat_t rtc_control_status = {0,0}; + ds3231_time_t rtc_time = {0,0,0,1,1}; + ds3231_calendar_t rtc_calendar = {0,0,0,0}; + + rtc.set_cntl_stat_reg(rtc_control_status); + + //Get hour from user + get_user_input("\nPlease enter the hour (0-12): ", 0, 12, + &rtc_time.hours); + + //Get minutes from user + get_user_input("\nPlease enter the minute (0-59): ", 0, 59, + &rtc_time.minutes); + + + //Get seconds from user + get_user_input("\nPlease enter the second (0-59): ", 0, 59, + &rtc_time.seconds); + + //get day from user + get_user_input("Please enter day of week, 1 for Sunday (1-7): ", 1, + 7, &rtc_calendar.day); + + //get day of month from user + get_user_input("Please enter day of month (1-31): ", 1, 31, + &rtc_calendar.date); + + //get month from user + get_user_input("Please enter the month, 1 for January (1-12): ", 1, + 12, &rtc_calendar.month); + + //get year from user + get_user_input("Please enter the year (0-99): ",0, 99, + &rtc_calendar.year); + + //Set the time + rtc.set_time(rtc_time); + + //Set the calendar + rtc.set_calendar(rtc_calendar); + + return 0; +} + + +/********************************************************************** +* Function: get_user_input() +* Parameters: message - user prompt +* min - minimum value of input +* max - maximum value of input +* member - pointer to struct member +* Returns: none +* +* Description: get time/date input from user +* +**********************************************************************/ +void get_user_input(char* message, uint8_t min, uint8_t max, uint8_t* member) +{ + + do { - + term.printf("\n%s", message); + term.scanf("%d", member); + + if((*(member)< min) || (*(member) > max)) + { + term.printf("\nERROR-RTFI"); + } } + while((*(member) < min) || (*(member) > max)); + } + \ No newline at end of file