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 Maxim Integrated

Committer:
j3
Date:
Wed Nov 26 20:18:26 2014 +0000
Revision:
1:37fd05629bd3
Parent:
0:f906040920d7
Child:
2:9b1e5efd9a09
demo

Who changed what in which revision?

UserRevisionLine numberNew contents of line
j3 0:f906040920d7 1 //Test Ard2Pmod Class
j3 0:f906040920d7 2
j3 0:f906040920d7 3
j3 0:f906040920d7 4 #include "ard2pmod.h"
j3 0:f906040920d7 5
j3 1:37fd05629bd3 6 void get_user_input(char* message, uint8_t min, uint8_t max, uint8_t* member);
j3 1:37fd05629bd3 7
j3 1:37fd05629bd3 8 Serial term(USBTX, USBRX);
j3 0:f906040920d7 9
j3 0:f906040920d7 10 int main(void)
j3 0:f906040920d7 11 {
j3 0:f906040920d7 12 /* available PMOD types
j3 1:37fd05629bd3 13 PMOD_TYPE_I2C_A,
j3 1:37fd05629bd3 14 PMOD_TYPE_I2C_B,
j3 1:37fd05629bd3 15 PMOD_TYPE_I2C_AB,
j3 0:f906040920d7 16 PMOD_TYPE_1_GPIO,
j3 0:f906040920d7 17 PMOD_TYPE_2_SPI,
j3 0:f906040920d7 18 PMOD_TYPE_3_UART,
j3 0:f906040920d7 19 PMOD_TYPE_4_UART,
j3 0:f906040920d7 20 PMOD_TYPE_5_HBRIDGE,
j3 0:f906040920d7 21 PMOD_TYPE_6_HBRIDGE
j3 0:f906040920d7 22 */
j3 1:37fd05629bd3 23 Ard2Pmod ard2pmod(PMOD_TYPE_I2C_AB);
j3 0:f906040920d7 24
j3 1:37fd05629bd3 25 //use to wiggle lines for PMOD_TYPE_1_GPIO
j3 1:37fd05629bd3 26 //BusOut pmod_A(D10, D11, D12, D13);
j3 1:37fd05629bd3 27 //BusOut pmod_B(D4, D5, D6, D7);
j3 1:37fd05629bd3 28
j3 1:37fd05629bd3 29 //DS3231 rtc variables
j3 1:37fd05629bd3 30
j3 1:37fd05629bd3 31 //default, use bit masks in ds3231.h for desired operation
j3 1:37fd05629bd3 32 ds3231_cntl_stat_t rtc_control_status = {0,0};
j3 1:37fd05629bd3 33 ds3231_time_t rtc_time;
j3 1:37fd05629bd3 34 ds3231_calendar_t rtc_calendar;
j3 1:37fd05629bd3 35
j3 1:37fd05629bd3 36 ard2pmod.set_cntl_stat_reg(rtc_control_status);
j3 1:37fd05629bd3 37
j3 1:37fd05629bd3 38 //get day from user
j3 1:37fd05629bd3 39 get_user_input("\nPlease enter day of week, 1 for Sunday (1-7): ", 1,
j3 1:37fd05629bd3 40 7, &rtc_calendar.day);
j3 1:37fd05629bd3 41
j3 1:37fd05629bd3 42 //get day of month from user
j3 1:37fd05629bd3 43 get_user_input("\nPlease enter day of month (1-31): ", 1, 31,
j3 1:37fd05629bd3 44 &rtc_calendar.date);
j3 1:37fd05629bd3 45
j3 1:37fd05629bd3 46 //get month from user
j3 1:37fd05629bd3 47 get_user_input("\nPlease enter the month, 1 for January (1-12): ", 1,
j3 1:37fd05629bd3 48 12, &rtc_calendar.month);
j3 1:37fd05629bd3 49
j3 1:37fd05629bd3 50 //get year from user
j3 1:37fd05629bd3 51 get_user_input("\nPlease enter the year (0-99): ",0, 99,
j3 1:37fd05629bd3 52 &rtc_calendar.year);
j3 1:37fd05629bd3 53
j3 1:37fd05629bd3 54 //Get time mode
j3 1:37fd05629bd3 55 get_user_input("\nWhat time mode? 1 for 12hr 0 for 24hr: ", 0, 1,
j3 1:37fd05629bd3 56 (uint8_t*) &rtc_time.mode);
j3 1:37fd05629bd3 57
j3 1:37fd05629bd3 58 if(rtc_time.mode)
j3 1:37fd05629bd3 59 {
j3 1:37fd05629bd3 60 //Get AM/PM status
j3 1:37fd05629bd3 61 get_user_input("\nIs it AM or PM? 0 for AM 1 for PM: ", 0, 1,
j3 1:37fd05629bd3 62 (uint8_t*) &rtc_time.am_pm);
j3 1:37fd05629bd3 63 //Get hour from user
j3 1:37fd05629bd3 64 get_user_input("\nPlease enter the hour (1-12): ", 1, 12,
j3 1:37fd05629bd3 65 &rtc_time.hours);
j3 1:37fd05629bd3 66 }
j3 1:37fd05629bd3 67 else
j3 1:37fd05629bd3 68 {
j3 1:37fd05629bd3 69 //Get hour from user
j3 1:37fd05629bd3 70 get_user_input("\nPlease enter the hour (0-23): ", 0, 23,
j3 1:37fd05629bd3 71 &rtc_time.hours);
j3 1:37fd05629bd3 72 }
j3 1:37fd05629bd3 73
j3 1:37fd05629bd3 74 //Get minutes from user
j3 1:37fd05629bd3 75 get_user_input("\nPlease enter the minute (0-59): ", 0, 59,
j3 1:37fd05629bd3 76 &rtc_time.minutes);
j3 1:37fd05629bd3 77
j3 1:37fd05629bd3 78
j3 1:37fd05629bd3 79 //Get seconds from user
j3 1:37fd05629bd3 80 get_user_input("\nPlease enter the second (0-59): ", 0, 59,
j3 1:37fd05629bd3 81 &rtc_time.seconds);
j3 1:37fd05629bd3 82
j3 1:37fd05629bd3 83
j3 1:37fd05629bd3 84
j3 1:37fd05629bd3 85 //Set the time
j3 1:37fd05629bd3 86 ard2pmod.set_time(rtc_time);
j3 1:37fd05629bd3 87
j3 1:37fd05629bd3 88 //Set the calendar
j3 1:37fd05629bd3 89 ard2pmod.set_calendar(rtc_calendar);
j3 0:f906040920d7 90
j3 0:f906040920d7 91 for(;;)
j3 0:f906040920d7 92 {
j3 1:37fd05629bd3 93 wait(1.0);
j3 0:f906040920d7 94
j3 1:37fd05629bd3 95 ard2pmod.get_time(&rtc_time);
j3 1:37fd05629bd3 96 ard2pmod.get_calendar(&rtc_calendar);
j3 1:37fd05629bd3 97
j3 1:37fd05629bd3 98 term.printf("\n\nRTC Date and Time = %d/%d/%d ",
j3 1:37fd05629bd3 99 rtc_calendar.month, rtc_calendar.date, rtc_calendar.year);
j3 1:37fd05629bd3 100
j3 1:37fd05629bd3 101 if(rtc_time.mode)
j3 1:37fd05629bd3 102 {
j3 1:37fd05629bd3 103 if(rtc_time.am_pm)
j3 1:37fd05629bd3 104 {
j3 1:37fd05629bd3 105 term.printf(" %d:%d:%d PM",
j3 1:37fd05629bd3 106 rtc_time.hours, rtc_time.minutes, rtc_time.seconds);
j3 1:37fd05629bd3 107 }
j3 1:37fd05629bd3 108 else
j3 1:37fd05629bd3 109 {
j3 1:37fd05629bd3 110 term.printf(" %d:%d:%d AM",
j3 1:37fd05629bd3 111 rtc_time.hours, rtc_time.minutes, rtc_time.seconds);
j3 1:37fd05629bd3 112 }
j3 1:37fd05629bd3 113 }
j3 1:37fd05629bd3 114 else
j3 1:37fd05629bd3 115 {
j3 1:37fd05629bd3 116 term.printf(" %d:%d:%d",
j3 1:37fd05629bd3 117 rtc_time.hours, rtc_time.minutes, rtc_time.seconds);
j3 1:37fd05629bd3 118 }
j3 1:37fd05629bd3 119
j3 1:37fd05629bd3 120 }//loop
j3 1:37fd05629bd3 121 }
j3 1:37fd05629bd3 122
j3 1:37fd05629bd3 123
j3 1:37fd05629bd3 124 /**********************************************************************
j3 1:37fd05629bd3 125 * Function: get_user_input()
j3 1:37fd05629bd3 126 * Parameters: message - user prompt
j3 1:37fd05629bd3 127 * min - minimum value of input
j3 1:37fd05629bd3 128 * max - maximum value of input
j3 1:37fd05629bd3 129 * member - pointer to struct member
j3 1:37fd05629bd3 130 * Returns: none
j3 1:37fd05629bd3 131 *
j3 1:37fd05629bd3 132 * Description: get time/date input from user
j3 1:37fd05629bd3 133 *
j3 1:37fd05629bd3 134 **********************************************************************/
j3 1:37fd05629bd3 135 void get_user_input(char* message, uint8_t min, uint8_t max, uint8_t* member)
j3 1:37fd05629bd3 136 {
j3 1:37fd05629bd3 137 uint8_t temp;
j3 1:37fd05629bd3 138
j3 1:37fd05629bd3 139 do
j3 1:37fd05629bd3 140 {
j3 1:37fd05629bd3 141 term.printf("\n%s", message);
j3 1:37fd05629bd3 142
j3 1:37fd05629bd3 143 //for some reason mbed doesn't like a pointer to a member in scanf
j3 1:37fd05629bd3 144 //term.scanf("%d", member); works with gcc on RPi
j3 1:37fd05629bd3 145 term.scanf("%d", &temp);
j3 1:37fd05629bd3 146 *member = temp;
j3 1:37fd05629bd3 147
j3 1:37fd05629bd3 148 if((*(member)< min) || (*(member) > max))
j3 1:37fd05629bd3 149 {
j3 1:37fd05629bd3 150 term.printf("\nERROR-RTI");
j3 1:37fd05629bd3 151 }
j3 0:f906040920d7 152 }
j3 1:37fd05629bd3 153 while((*(member) < min) || (*(member) > max));
j3 1:37fd05629bd3 154 }