CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Setting RTC

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
MarkchchPIC



Joined: 14 Jan 2015
Posts: 18
Location: Christchurch New Zealand

View user's profile Send private message

Setting RTC
PostPosted: Thu Jun 18, 2020 10:44 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Fri Jun 19, 2020 12:32 am     Reply with quote

__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

View user's profile Send private message

PostPosted: Fri Jun 19, 2020 12:36 am     Reply with quote

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

View user's profile Send private message

PostPosted: Fri Jun 19, 2020 1:40 am     Reply with quote

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!... Very Happy
MarkchchPIC



Joined: 14 Jan 2015
Posts: 18
Location: Christchurch New Zealand

View user's profile Send private message

PostPosted: Fri Jun 19, 2020 3:15 am     Reply with quote

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

View user's profile Send private message

PostPosted: Fri Jun 19, 2020 3:43 am     Reply with quote

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

View user's profile Send private message

PostPosted: Fri Jun 19, 2020 3:54 am     Reply with quote

Thanks for you help and explanation.
Cheers
Mark
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Jun 19, 2020 4:00 am     Reply with quote

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

View user's profile Send private message

PostPosted: Fri Jun 19, 2020 4:57 am     Reply with quote

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

View user's profile Send private message

PostPosted: Fri Jun 19, 2020 5:30 am     Reply with quote

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

View user's profile Send private message

PostPosted: Fri Jun 19, 2020 6:09 am     Reply with quote

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.... :(
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group