Before jumping right into our micro-controller lets try to make some auxiliary functions we will need first, these functions can be written, compiled and tested on the PC and later on you can easily incorporated in the main project for your microcontroller, I’m only show you the requirements because you will be in charge of the implementation. The use of functions, itoa, atoi and sprintf is forbidden.
Function to validate time in 24 hour format
unsigned char Validate_Time( unsigned char hour, unsigned char minutes, unsigned char seconds );
The should validate the parameters pass form a valid time in 24 hour format, the function will receive as parameters the hour, minutes and seconds in decimal format. It shall return a 1 if the parameters makes a valid time or zero if not.
- hours.- hours in 24h format
- minutes.- minutes
- seconds.- seconds
Function to validate date
unsigned char Validate_Date( unsigned char days, unsigned char month, unsigned short year );
Write a function to validate date in day of the month, month (from 1 to 12) and year (four digits from 1900 to 2100) format, the function will receive as parameters the date. It shall return a 1 if the parameters makes a valid date or zero if not. The leap years shall be take into consideration
- month.- month (from 1 to 12)
- day.- day of the month
- year.- year
Function to validate a leap year
unsigned char Validate_LeapYear( unsigned short year );
Write a function to determine if the year is a leap year or not, return 1 if leap otherwise return 0
- year.- year
Function to calculate the day of the week
unsigned char Weekday( unsigned char days, unsigned char month, unsigned short year );
Write a function to calculate the day of the week from a valid day, month and year. It will receive a valid date and return the day of the week from Sunday (0) to Saturday (6)
- month.- month (from 1 to 12)
- day.- day of the month
- year.- year
Function to convert a string of signed numbers to its decimal value
long String_To_Integer( char *string );
The function will take a null terminated string representing a signed number in decimal format and return is equivalent in integer format, when negative number representation is passe, the string should start with '-' character
- string.- address of the an array of character null terminated
Function to convert a signed decimal number to string of characters
void Integer_To_String( char *string, long number );
The function will take a signed number in decimal format and return a string representation, when the number is negative the string returned should start with a '-' character
- string.- address of an array where the string representation should be placed
- number.- the number that will be converted to string representation
Function to convert time to a string representation
void Time_String( char *string, unsigned char hours, unsigned char minutes, unsigned char seconds );
The function shall receive time in 24h format and return a string representation with the following format “00:00:00“. Remember is a string therefore is an array of ASCII character with a null termination '\0'. Example: “15:30:00“, All paramter shall be received in decimal format.
- string.- pointer to array address to store the time string
- hours.- hours in 24h format
- minutes.- minutes
- seconds.- seconds
Function to convert date to a string representation
void Date_String( char *string, unsigned char month, unsigned char day, unsigned short year, unsigned char weekday );
The function shall receive date in day of the month, month and year and return a string representation with the following format “Mon dd, yyyy Dy“. Remember is a string therefore is an array of ASCII character with a null termination '\0'. Example: “Jun 24, 1984 Lu“. All paramter shall be received in decimal format.
- string.- pointer to array address to store the time string
- month.- month (from 1 to 12)
- day.- day of the month
- year.- year
- weekday.- day of the week
I know that was pretty easy for a pro coder like you, so increase the challenge by a writing the corresponding unit testing using ceedling,