I am doing a project which will get a time data from external Real time clock chip. The data format of the RTC is in BCD form. How can i convert BCD data to real value? is there can built-in function to do that? pls help
Have you read this thread? http://www.keil.com/forum/docs/thread1476.asp If not perhaps a little pixie dust will help ;-)
What's the "real" value for real time clock data? A data/time string? 32-bit unsigned integer number of seconds since January 1, 1970? A structure of integers for year, month, day, hours, minutes, seconds? I don't know of any standard C functions that deal with BCD representation. Conversion to a "normal" two's-complement integer is pretty straightforward.
void showTime (void) { // 24 Hour clock unsigned long cTime; // RTC Value int cSeconds = 0; // cTime/1 int cMinutes = 0; // cTime/60 int cHours = 0; // cTime/3600 char cBuffer [8]; // Stores formatted string cTime = RTC_RTCH * 0x10000 + RTC_RTCL; // Get value of RTC cHours = (int) (cTime / 3600) - ((int) (cTime / 86400) * 24); cMinutes = (int) ((cTime / 60) - ((cTime / 3600) * 60)); cSeconds = (int) (cTime - ((cTime / 60) * 60)); sprintf (cBuffer, "%02u:%02u:%02u", cHours, cMinutes, cSeconds); printf (" %s \r", cBuffer); }
I am positive that the OP has patiently waited since 2/27/03 on your reply Erik
"I am positive that the OP has patiently waited since 2/27/03 on your reply" Plus, after a 2.5-year wait, now only to be disappointed that the reply has nothing to do with BCD conversion.
"Plus, after a 2.5-year wait, now only to be disappointed that the reply has nothing to do with BCD conversion" And it overruns a buffer...
Yeah - but it was free!! ;-)
It's a takee, the opposite of a gimme. "u will pls takee my sample codes and be forever cursed with my bugs"