Ejemplo RTC DS3231

Dependencies:   mbed ds3231

Committer:
j3
Date:
Thu Nov 20 00:04:13 2014 +0000
Revision:
1:7db4a1cc7abb
Parent:
0:6be499dd402a
Child:
2:76cd47a603b5
working

Who changed what in which revision?

UserRevisionLine numberNew contents of line
j3 0:6be499dd402a 1 //Test Ds3231 class
j3 0:6be499dd402a 2
j3 0:6be499dd402a 3 #include "ds3231.h"
j3 0:6be499dd402a 4
j3 1:7db4a1cc7abb 5 void get_user_input(char* message, uint8_t min, uint8_t max, uint8_t* member);
j3 1:7db4a1cc7abb 6
j3 1:7db4a1cc7abb 7 Serial term(USBTX, USBRX);
j3 0:6be499dd402a 8
j3 0:6be499dd402a 9 int main(void)
j3 0:6be499dd402a 10 {
j3 1:7db4a1cc7abb 11 //rtc object
j3 0:6be499dd402a 12 Ds3231 rtc(D14, D15);
j3 0:6be499dd402a 13
j3 1:7db4a1cc7abb 14 //DS3231 rtc variables
j3 1:7db4a1cc7abb 15 ds3231_cntl_stat_t rtc_control_status = {0,0};
j3 1:7db4a1cc7abb 16 ds3231_time_t rtc_time = {0,0,0,1,1};
j3 1:7db4a1cc7abb 17 ds3231_calendar_t rtc_calendar = {0,0,0,0};
j3 1:7db4a1cc7abb 18
j3 1:7db4a1cc7abb 19 rtc.set_cntl_stat_reg(rtc_control_status);
j3 1:7db4a1cc7abb 20
j3 1:7db4a1cc7abb 21 //Get hour from user
j3 1:7db4a1cc7abb 22 get_user_input("\nPlease enter the hour (0-12): ", 0, 12,
j3 1:7db4a1cc7abb 23 &rtc_time.hours);
j3 1:7db4a1cc7abb 24
j3 1:7db4a1cc7abb 25 //Get minutes from user
j3 1:7db4a1cc7abb 26 get_user_input("\nPlease enter the minute (0-59): ", 0, 59,
j3 1:7db4a1cc7abb 27 &rtc_time.minutes);
j3 1:7db4a1cc7abb 28
j3 1:7db4a1cc7abb 29
j3 1:7db4a1cc7abb 30 //Get seconds from user
j3 1:7db4a1cc7abb 31 get_user_input("\nPlease enter the second (0-59): ", 0, 59,
j3 1:7db4a1cc7abb 32 &rtc_time.seconds);
j3 1:7db4a1cc7abb 33
j3 1:7db4a1cc7abb 34 //get day from user
j3 1:7db4a1cc7abb 35 get_user_input("Please enter day of week, 1 for Sunday (1-7): ", 1,
j3 1:7db4a1cc7abb 36 7, &rtc_calendar.day);
j3 1:7db4a1cc7abb 37
j3 1:7db4a1cc7abb 38 //get day of month from user
j3 1:7db4a1cc7abb 39 get_user_input("Please enter day of month (1-31): ", 1, 31,
j3 1:7db4a1cc7abb 40 &rtc_calendar.date);
j3 1:7db4a1cc7abb 41
j3 1:7db4a1cc7abb 42 //get month from user
j3 1:7db4a1cc7abb 43 get_user_input("Please enter the month, 1 for January (1-12): ", 1,
j3 1:7db4a1cc7abb 44 12, &rtc_calendar.month);
j3 1:7db4a1cc7abb 45
j3 1:7db4a1cc7abb 46 //get year from user
j3 1:7db4a1cc7abb 47 get_user_input("Please enter the year (0-99): ",0, 99,
j3 1:7db4a1cc7abb 48 &rtc_calendar.year);
j3 1:7db4a1cc7abb 49
j3 1:7db4a1cc7abb 50 //Set the time
j3 1:7db4a1cc7abb 51 rtc.set_time(rtc_time);
j3 1:7db4a1cc7abb 52
j3 1:7db4a1cc7abb 53 //Set the calendar
j3 1:7db4a1cc7abb 54 rtc.set_calendar(rtc_calendar);
j3 1:7db4a1cc7abb 55
j3 1:7db4a1cc7abb 56 return 0;
j3 1:7db4a1cc7abb 57 }
j3 1:7db4a1cc7abb 58
j3 1:7db4a1cc7abb 59
j3 1:7db4a1cc7abb 60 /**********************************************************************
j3 1:7db4a1cc7abb 61 * Function: get_user_input()
j3 1:7db4a1cc7abb 62 * Parameters: message - user prompt
j3 1:7db4a1cc7abb 63 * min - minimum value of input
j3 1:7db4a1cc7abb 64 * max - maximum value of input
j3 1:7db4a1cc7abb 65 * member - pointer to struct member
j3 1:7db4a1cc7abb 66 * Returns: none
j3 1:7db4a1cc7abb 67 *
j3 1:7db4a1cc7abb 68 * Description: get time/date input from user
j3 1:7db4a1cc7abb 69 *
j3 1:7db4a1cc7abb 70 **********************************************************************/
j3 1:7db4a1cc7abb 71 void get_user_input(char* message, uint8_t min, uint8_t max, uint8_t* member)
j3 1:7db4a1cc7abb 72 {
j3 1:7db4a1cc7abb 73
j3 1:7db4a1cc7abb 74 do
j3 0:6be499dd402a 75 {
j3 1:7db4a1cc7abb 76 term.printf("\n%s", message);
j3 1:7db4a1cc7abb 77 term.scanf("%d", member);
j3 1:7db4a1cc7abb 78
j3 1:7db4a1cc7abb 79 if((*(member)< min) || (*(member) > max))
j3 1:7db4a1cc7abb 80 {
j3 1:7db4a1cc7abb 81 term.printf("\nERROR-RTFI");
j3 1:7db4a1cc7abb 82 }
j3 0:6be499dd402a 83 }
j3 1:7db4a1cc7abb 84 while((*(member) < min) || (*(member) > max));
j3 1:7db4a1cc7abb 85
j3 0:6be499dd402a 86 }
j3 1:7db4a1cc7abb 87
j3 0:6be499dd402a 88