View previous topic :: View next topic |
Author |
Message |
ktallevi
Joined: 17 Dec 2005 Posts: 58
|
Converting a unix time stamp |
Posted: Tue Oct 21, 2008 12:49 pm |
|
|
Does CCS have any built-in functions to convert a unix time stamp to something usable.
Eg. 685586AC (hex) -> 16:05:00 June 20 2025
thanks. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Oct 21, 2008 4:09 pm |
|
|
The ctime() function does the conversion from a Unix Timestamp to
a readable date and time. That function is the rtctimer.c file, which
is included with the CCS compiler. Here is the file location:
Quote: | c:\Program Files\picc\Drivers\rtctimer.c |
The test program shown below has the following output:
Quote: | Fri Jun 20 16:05:00 2025 |
Code: | #include <16F877.H>
#fuses XT, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)
#include <rtctimer.c>
//====================================
void main()
{
int32 tTime;
int8 tString[80];
tTime = 0x685586AC;
ctime(&tTime, tString);
printf(tString);
while(1);
} |
|
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Tue Oct 21, 2008 4:25 pm |
|
|
Not for UNIX date/time, but in the Code Library are some optimized time routines for years 2001 - 2098.
http://www.ccsinfo.com/forum/viewtopic.php?t=25611
Add or subtract the number of seconds from 1-1-1970 to 1-1-2001 and you are up and running. |
|
|
crystal_lattice
Joined: 13 Jun 2006 Posts: 164
|
|
Posted: Wed Oct 22, 2008 12:28 am |
|
|
Or have a look at the AN517 appnote from Maxim/Dallas. |
|
|
D-Kens
Joined: 09 May 2005 Posts: 35 Location: Toulouse (France)
|
|
Posted: Mon Jun 08, 2009 3:45 am |
|
|
PCM programmer wrote: | The ctime() function does the conversion from a Unix Timestamp to a readable date and time. That function is the rtctimer.c file, which is included with the CCS compiler. |
Nice !!! I didn't know there were tools to work with Unix timestamps... But... Euh... How comes I don't have the RTCTimer library in my Drivers directory ? |
|
|
Ttelmah Guest
|
|
Posted: Mon Jun 08, 2009 5:06 am |
|
|
How old is your compiler?.
This library, only appeared with the V4 releases. It came out, mid 2007.
Best Wishes |
|
|
|