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 support@ccsinfo.com

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
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