Could some body in this forum advise me with a simple code on how to diplay DATE and TIME using printf() statement. I tried cut and paste the one posted here, and it did not even compile ... whole bunch of syntax errors !!!! Thanks in advance, JIMMY
Keil C does not have the standard functions found in time.h. Knowing the real time-of-day (TOD) implies that you have access to some hardware that tracks TOD. Many embedded systems don't, and may not even care about TOD. Those that do care will have wildly varying implementations of the hardware. There's no way Keil could support them all. If you don't have a TOD clock, you can implement it in software using a timer tick interrupt, and counting days, hours, minutes, seconds, down to whatever resolution you need. Two common methods are to actually count days, hours, etc., in separate integers, doing the modulo wraparound as appropriate, or to continuously count one measure in a big integer, and convert to Y/M/D/H/S as required. (Unix, for example, traditionally counts seconds since January 1, 1970, in a 32-bit integer.) The software will need some means to set the clock correctly once it boots. Perhaps that's a human pushing buttons, maybe it's a network protocol to fetch the time, maybe just TOD from time "zero" is good enough. So, the first question to answer is Andy's "how are you obtaining date and time"? Once you know that, then you'll know the exact format the bits that represent your time are in. Then you'll be able to figure out how to convert it to some desired time format (text output over a UART? 7-segment display? Alpha LCD screen?) You might consider implementing the standard C library time functions on top of your hardware. If so, displaying the current time might be as simple as "printf(ctime())". If your application is really serious about time (say, an astronomical instrument or maybe navigation), even tracking the actual, precise, time of day gets really complicated.