Giovani Cardona
/
4_1_DS3231demo
Ejemplo RTC DS3231
main.cpp
- Committer:
- j3
- Date:
- 2014-11-20
- Revision:
- 1:7db4a1cc7abb
- Parent:
- 0:6be499dd402a
- Child:
- 2:76cd47a603b5
File content as of revision 1:7db4a1cc7abb:
//Test Ds3231 class #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) { //rtc object Ds3231 rtc(D14, D15); //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)); }