PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Feb 08, 2010 2:07 pm |
|
|
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);
} |
|
|