Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
main.cpp
- Committer:
- j3
- Date:
- 2014-11-26
- Revision:
- 1:37fd05629bd3
- Parent:
- 0:f906040920d7
- Child:
- 2:9b1e5efd9a09
File content as of revision 1:37fd05629bd3:
//Test Ard2Pmod Class
#include "ard2pmod.h"
void get_user_input(char* message, uint8_t min, uint8_t max, uint8_t* member);
Serial term(USBTX, USBRX);
int main(void)
{
/* available PMOD types
PMOD_TYPE_I2C_A,
PMOD_TYPE_I2C_B,
PMOD_TYPE_I2C_AB,
PMOD_TYPE_1_GPIO,
PMOD_TYPE_2_SPI,
PMOD_TYPE_3_UART,
PMOD_TYPE_4_UART,
PMOD_TYPE_5_HBRIDGE,
PMOD_TYPE_6_HBRIDGE
*/
Ard2Pmod ard2pmod(PMOD_TYPE_I2C_AB);
//use to wiggle lines for PMOD_TYPE_1_GPIO
//BusOut pmod_A(D10, D11, D12, D13);
//BusOut pmod_B(D4, D5, D6, D7);
//DS3231 rtc variables
//default, use bit masks in ds3231.h for desired operation
ds3231_cntl_stat_t rtc_control_status = {0,0};
ds3231_time_t rtc_time;
ds3231_calendar_t rtc_calendar;
ard2pmod.set_cntl_stat_reg(rtc_control_status);
//get day from user
get_user_input("\nPlease enter day of week, 1 for Sunday (1-7): ", 1,
7, &rtc_calendar.day);
//get day of month from user
get_user_input("\nPlease enter day of month (1-31): ", 1, 31,
&rtc_calendar.date);
//get month from user
get_user_input("\nPlease enter the month, 1 for January (1-12): ", 1,
12, &rtc_calendar.month);
//get year from user
get_user_input("\nPlease enter the year (0-99): ",0, 99,
&rtc_calendar.year);
//Get time mode
get_user_input("\nWhat time mode? 1 for 12hr 0 for 24hr: ", 0, 1,
(uint8_t*) &rtc_time.mode);
if(rtc_time.mode)
{
//Get AM/PM status
get_user_input("\nIs it AM or PM? 0 for AM 1 for PM: ", 0, 1,
(uint8_t*) &rtc_time.am_pm);
//Get hour from user
get_user_input("\nPlease enter the hour (1-12): ", 1, 12,
&rtc_time.hours);
}
else
{
//Get hour from user
get_user_input("\nPlease enter the hour (0-23): ", 0, 23,
&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);
//Set the time
ard2pmod.set_time(rtc_time);
//Set the calendar
ard2pmod.set_calendar(rtc_calendar);
for(;;)
{
wait(1.0);
ard2pmod.get_time(&rtc_time);
ard2pmod.get_calendar(&rtc_calendar);
term.printf("\n\nRTC Date and Time = %d/%d/%d ",
rtc_calendar.month, rtc_calendar.date, rtc_calendar.year);
if(rtc_time.mode)
{
if(rtc_time.am_pm)
{
term.printf(" %d:%d:%d PM",
rtc_time.hours, rtc_time.minutes, rtc_time.seconds);
}
else
{
term.printf(" %d:%d:%d AM",
rtc_time.hours, rtc_time.minutes, rtc_time.seconds);
}
}
else
{
term.printf(" %d:%d:%d",
rtc_time.hours, rtc_time.minutes, rtc_time.seconds);
}
}//loop
}
/**********************************************************************
* 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)
{
uint8_t temp;
do
{
term.printf("\n%s", message);
//for some reason mbed doesn't like a pointer to a member in scanf
//term.scanf("%d", member); works with gcc on RPi
term.scanf("%d", &temp);
*member = temp;
if((*(member)< min) || (*(member) > max))
{
term.printf("\nERROR-RTI");
}
}
while((*(member) < min) || (*(member) > max));
}
MAXREFDES72# Ard2Pmod Shield