View previous topic :: View next topic |
Author |
Message |
MarkchchPIC
Joined: 14 Jan 2015 Posts: 18 Location: Christchurch New Zealand
|
Setting RTC |
Posted: Thu Jun 18, 2020 10:44 pm |
|
|
Hi All
Is there a way to extract the information from __DATE__ and
__TIME__ into an array to update an RTC like DS1307?
I have searched for information onthe strucure of__DATE__
and _TIME__ to no avail.
Any thoughts or clues to point me in the right direction would be appreciated.
Cheers
Mark |
|
|
jeremiah
Joined: 20 Jul 2010 Posts: 1354
|
|
Posted: Fri Jun 19, 2020 12:32 am |
|
|
__DATE__ and __TIME__ give the date and time of when the code was compiled, so not really useful for updating an RTC. You are gonna have to either manually do it or get the time from something like a GPS module (or some module that provides time info). |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Jun 19, 2020 12:36 am |
|
|
My first question is, do you know these values are created at
compile-time by the compiler. It gets the current date and time
from the Windows O/S. These are fixed values. There is no secret
software RTC running in CCS compiled code.
Do you still want to use this data ? |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19538
|
|
Posted: Fri Jun 19, 2020 1:40 am |
|
|
I love the idea that the code is going to miraculously 'know' the date and
time... It'd solve a lot of problems if it did!... |
|
|
MarkchchPIC
Joined: 14 Jan 2015 Posts: 18 Location: Christchurch New Zealand
|
|
Posted: Fri Jun 19, 2020 3:15 am |
|
|
Sorry Guys I am not good at explaining. I understand it is the OS time but my question is more about it's format. I want to take the information, deconstruct it into either ints or chars and use this to load my RTC. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19538
|
|
Posted: Fri Jun 19, 2020 3:43 am |
|
|
The manual does tell you all this. It is a constant string.
So:
Code: |
char mystring[20];
sprintf(mystring,__date__);
|
Will result in 'mystring', containing the date in the format xx-mon-yy,
where 'xx' is the day of the month, 'mon' is the month in text alpha form
(abbreviations as in 'MonthAbbreviations', in time.c), and 'yy' is the
two digit year number.
Similarly:
Code: |
sprintf(mystring,__time__);
|
Will give 'mystring' containing the time in the format hh:mm:ss.
You'd obviously have to use string operations to read the individual parts
out of this. A lot of work for something that is of no use at all to set a clock. |
|
|
MarkchchPIC
Joined: 14 Jan 2015 Posts: 18 Location: Christchurch New Zealand
|
|
Posted: Fri Jun 19, 2020 3:54 am |
|
|
Thanks for you help and explanation.
Cheers
Mark |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Jun 19, 2020 4:00 am |
|
|
Tell us why you want to set the RTC to the compile date and time.
Explain how this will help your project work. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9243 Location: Greensville,Ontario
|
|
Posted: Fri Jun 19, 2020 4:57 am |
|
|
Actually it's a clever way of getting date/time into the 1307 RTC but....the PIC time will be several seconds delayed from the OS time.
From the end of the compile to the PIC running the program will take several seconds. I think 5-10 seconds might be a good guess.
I often 'hardcode' the date/time info, then run a 'setupRTC' function once on projects that have no access to outside time (no PC link, no GPS) so I can see this approach being useful as long as you're fine with the delay.
Now if you can see the 'delay' is always say 7 seconds, you could get OS time then add 7 seconds then use THAT new time to program the RTC. Then you'd be within 1 second of the OS time.
great now I want to try coding for that but coffee pot's busted...
Jay |
|
|
MarkchchPIC
Joined: 14 Jan 2015 Posts: 18 Location: Christchurch New Zealand
|
|
Posted: Fri Jun 19, 2020 5:30 am |
|
|
It was simply an idea to prime the RTC without having to add switches for setting the time. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19538
|
|
Posted: Fri Jun 19, 2020 6:09 am |
|
|
Yes, if you always re-compile before loading, and can build in an offset
for the compile time, and then the programming time, it could be a reasonable
'sneaky' way for a situation where there is nothing to set the chip. Only issue
is (of course), that you'd have to reprogram every time you want to reset the
time.... :( |
|
|
|