Date /time stamp for PICS?

For questions and comments on programming in general. And for any items that don't fit into the forums below.

Moderators: Benj, Mods

Post Reply
User avatar
achillis1
Posts: 347
Joined: Thu Oct 09, 2008 9:19 am
Has thanked: 91 times
Been thanked: 8 times

Date /time stamp for PICS?

Post by achillis1 »

Hello,

Does anyone has a macro that is capable to calculate date/time/year? I am making a hardware that will be used for timekeeping.
I have the RTC clock DS1307 which works with I2C protocol. I have downloaded some fcf files from the forum concerning the DS1307 but I had no luck reading(succesfully|) the registers of the DS1307!
I would appreciate any help.
Thank you in advance.
Best Regards,
Achillis.

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Date /time stamp for PICS?

Post by Benj »

Hello

To calculate the date should be fairly simple and would follow on from a clock example.

Eg have a timer interrupt running to catch each second of a day.


second = (second + 1) MOD 60

if second = 0 then min = (min + 1) mod 60

if min = 0 then hour = (hour + 1) mod 24

if hour = 0 then day = (day + 1) mod DAYSINMONTH[month]

if day = 0 then month = (month + 1) mod 12

etc

the DAYSINMONTH array would need to have 12 locations each containing the number of days in that month.

You could use a similar approach or leap years.

Or you could use the RTC. Some of the I2C interface examples may be of some help to you.

User avatar
achillis1
Posts: 347
Joined: Thu Oct 09, 2008 9:19 am
Has thanked: 91 times
Been thanked: 8 times

Re: Date /time stamp for PICS?

Post by achillis1 »

Hello,

Thank you Ben for the help.
I will have in mind the time keeping method you are suggesting.
Finally I have managed to manipulate the RTC registers(with lots of help by you!) and I can read them, print them and increment and decrement within the program.
Thank you very much.

Best Regards,
Achillis.

doddy7
Posts: 1
Joined: Wed Dec 02, 2009 5:18 pm

Re: Date /time stamp for PICS?

Post by doddy7 »

achillis1 wrote:Hello,

Thank you Ben for the help.
I will have in mind the time keeping method you are suggesting.
Finally I have managed to manipulate the RTC registers(with lots of help by you!) and I can read them, print them and increment and decrement within the program.
Thank you very much.

Best Regards,
Achillis.

Hi there,
I am working on an almost similar situation, where I have to display mins and secs on a 7 segment display. Naturally when the seconds ‘tick over’ from 59 to 0, then the minutes display is incremented by 1. When timer display reaches 59 minutes and 59 seconds the display reset to zero and commence timing again.

Secondly i have to modify mins and secs program to display hours and minutes in both 12 hour and 24 hour clock mode switchable by pressing PIC port button. and making this input latch so that it stays in one mode until the said button is pressed again.

I managed to write the following sub routine(USING C2C IDE), which appear to work fine for the first task, and not for the second one. ANY HELP?

HERE S MY SUB ROUTINE:

while (1) {

while ( get_button () == 0 ) ;

units = units+1 ;
if ( units > 9 ) {
units = 0 ;
tens = tens + 1 ;
if ( tens > 5 ) {
tens = 0 ;
huns=huns+1 ;
if ( huns > 9 ) {
huns = 0 ;
thous=thous+1 ;
if ( thous > 5 ) {
thous = 0 ;
}
}
}
}

display ( units, 3 ) ;
display ( tens, 2 ) ;
display ( huns, 1 ) ;
display ( thous, 0 ) ;

while ( get_button () == 1 ) ;
}
}

Post Reply