2010-05-26 10:34 PM
set date then auto increment
2011-05-17 04:52 AM
You should examine how the C/UNIX time() functions work.
The 32-bit value holds the number of seconds since some epoch (1-Jan-1970 for UNIX as I recall). Calendering is performed by converting DD:MM:YYYY,HH:MM:SS in to a second count, and functions to perform the reverse can take a second count and decode it into a human readable form.2011-05-17 04:52 AM
The value being outputted by the RTC clock is in UNIX format.Example only shows UNIX time being converted to hour, minute and seconds. How do you get the value for year, month and day.
2011-05-17 04:52 AM
Seriously?
http://www.google.com./#hl=en&q=gmtime+source
http://www.google.com./#hl=en&q=mktime+source
Here is a simple implementation I built from first principles, handles UNIX time in the range 1970 through 2099 #define SECONDS_IN_DAY (24 * 60 * 60) // 84600 void decodetime(DWORD tick) { DWORD seconds; DWORD day; DWORD month; DWORD year; day = tick / SECONDS_IN_DAY; seconds = tick % SECONDS_IN_DAY; // 1900 and 2100 are not leap years, 2000 is. (ie divisible by 100, but not 400) // This method is good for 1901 thru 2099, where all years divisible by 4 are leaps year = day / 1461; // 365*3 + 365 day = day % 1461; year = (year * 4) + 1970; while(1) // Handle 4 Year span { if ((year & 3) == 0) // Leap Year { if (day > 365) // Over Year { day -= 366; year++; } else break; } else { if (day > 364) // Over Year { day -= 365; year++; } else break; } } month = 0; if ((year & 3) == 0) // Leap Year { const char daytbl[] = { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; // Days in Months while(day >= (DWORD)daytbl[month]) day -= daytbl[month++]; } else { const char daytbl[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; while(day >= (DWORD)daytbl[month]) day -= daytbl[month++]; } day++; // Zero based to One based month++; // Zero based to One based printf(''%2d %2d %4d %2d:%02d:%02d\n'',day,month,year, (seconds / (60 * 60)), ((seconds / 60) % 60), (seconds % 60) ); }2011-05-17 04:52 AM
You don't need floating point (%f) for any of this. Are you asking a separate question relating to floating point or are you still trying to find a solution to your calender problem? If a seperate question can I suggest you start a seperate thread?
Regards Trevor2011-05-17 04:52 AM
I found out that all values are in integer format, how do you output using float format, I tried using printf(''%f'',example) but the value displayed is wrong. It also doesn't accept #include ''math.h''. How do you solve this problem? Is it because of this code that only int values are allowed:
#ifdef __GNUC__
/* With GCC/RAISONANCE, small printf (option LD Linker->Libraries->Small printf
set to 'Yes') calls __io_putchar() */
#define PUTCHAR_PROTOTYPE int __io_putchar(int ch)
#else
#define PUTCHAR_PROTOTYPE int fputc(int ch, FILE *f)
#endif /* __GNUC__ *
2011-05-17 04:52 AM
I agree that you don't need to display floating point for displaying time since decimal points are not that significant. When I got the Unix time, I need to convert it to Julian day, where the result's decimal point is needed. Do you know if float is usable in ARM mcu's?
2011-05-17 04:52 AM
Floating point works on the STM32, you just need to be using the correct compiler, and settings. What exactly are you using.
So why exactly do you need floating point to compute the Julian date? If you need the time-of-day you can easily separate that from the seconds to get an integer day number. Pretty common formula I've used in the past. Googling some of the constants. http://mth.uct.ac.za/~lab/chap1/chap1.pdf Page 7 1.3.2 Given the year, month and day of the month, the Julian day is calculated as follows: Julian = (36525*year)/100 + (306001*(month+1))/10000 + day + 1720981 where month is 13 for Jan, 14 for Feb, 3 for Mar, 4 for Apr etc. For Jan and Feb, the year is reduced by 1. Write a script which asks for the day, month and year and calculates the Julian day. All variables must be of integer type. What is the Julian day for 7 Jun 2008? [The answer is 2454624]. In C int ComputeJulian(int Day, int Month, int Year) { int JulianDate; // Month 1-12 // Year 1901-2099, evaluated if (Month <= 2) { Year--; Month += 12; } JulianDate = (36525 * Year) / 100 + (306001 * (Month + 1)) / 10000 + Day + 1720981; return(JulianDate); }