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

Re: getting time from ds1307.

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



Joined: 15 Jan 2009
Posts: 60

View user's profile Send private message Visit poster's website

Re: getting time from ds1307.
PostPosted: Sun Feb 07, 2010 11:28 pm     Reply with quote

Hello Sir,

I used the ds1307 driver from your forum. Its Working Perfectly. But My Problem is, when i restart my PIC16f877a, then the time from the rtc also restarted.

Because i set the time by hardcoding in the initial stage.

So i need to get the time continuously instead of power cut or restart of PIC microcontroller etc.

Thanks and Regards,

Varadharaj Ellappan
_________________
embedding innovation in engineers
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Feb 08, 2010 12:44 am     Reply with quote

Read an eeprom location in the PIC. If it is a special value, such as 0x55,
then it means you have already set the date and time in the ds1307.
So then, don't set it again. Skip that code if the eeprom location = 0x55.

But if the eeprom location is not 0x55, then set the date and time in
the ds1307. Then write 0x55 to the eeprom location.
evaradharaj



Joined: 15 Jan 2009
Posts: 60

View user's profile Send private message Visit poster's website

which location?
PostPosted: Mon Feb 08, 2010 2:20 am     Reply with quote

Hai sir,

Thanks for your quick reply. Which location of the ds1307 EEPROM, i have to read? Can you specify it?
_________________
embedding innovation in engineers
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Feb 08, 2010 2:39 am     Reply with quote

I meant you could use any location in the PIC's data eeprom.
You could also use the "User area" NVRAM in the ds1307.
evaradharaj



Joined: 15 Jan 2009
Posts: 60

View user's profile Send private message Visit poster's website

writing data
PostPosted: Mon Feb 08, 2010 2:56 am     Reply with quote

Hai Sir,

Now i understood .. Please check my understanding is correct or not?

you have specified in your example 0x55 is user defined number set by user at the time of time set in RTC... Am i correct?
_________________
embedding innovation in engineers
pdl



Joined: 01 Jun 2005
Posts: 45
Location: UK

View user's profile Send private message

Drive
PostPosted: Mon Feb 08, 2010 4:32 am     Reply with quote

Hi evaradharaj

Could you point me to the link for the driver that you used. I have used one driver but when I put the code into a pic I get something like 45:48 come up and not the time. Any help would be great.

thanks

Pete
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Feb 08, 2010 2:07 pm     Reply with quote

Quote:

you have specified in your example 0x55 is user defined number set by
user at the time of time set in RTC... Am i correct?

Here's an example. The program shown below will run the initialization
code one time. After that, it sets a flag in eeprom to indicate that the
init code has been run. Anytime the PIC is turned on in the future, it
will read the init flag and see that it is set to 0x55, and it will not execute
the init code.

Here is the output of the program shown below. I program the PIC with
the ICD2. Then I turn on the PIC (or release it from reset). It runs
the first time, and does the initialization code. Then I cycle the power
several more times, but it does not run the init code again. That's the
desired behavior. This program shows how to implement a "run once"
initialization routine.
Quote:

Initialization Done !
Main code now running...
Main code now running...
Main code now running...
Main code now running...
Main code now running...
Main code now running...
Main code now running...

Code:

#include <16F877.H>
#fuses XT, NOWDT, BROWNOUT, PUT, NOLVP
#use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)

// Use a #rom statement to initialize eeprom address 0
// to the value of 0xFF when the PIC is programmed.
// This ensures that initial value of the eeprom init
// flag (at eeprom address 0) is not the same as the
// "init done" flag.
#rom 0x2100 = {0xFF}   // EEprom address for 16F-series PICs

#define INIT_DONE  0x55
#define INIT_DONE_FLAG_ADDR 0x00  // First byte addr in eeprom

//======================================
void main()
{
// Check if the initialization has been done.  If not,
// then do it now.
if(read_eeprom(INIT_DONE_FLAG_ADDR) != INIT_DONE)
  {
   // Put your init code here.

   printf("Initialization Done !\n\r");  // Optional message

   // Then set the flag to show we have done the init.
   write_eeprom(INIT_DONE_FLAG_ADDR, INIT_DONE);
  }

printf("Main code now running...\n\r");  // Optional message
// Put your main code here.

while(1);
}
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