At 01:57 PM 1/15/03 +0200, you wrote: >Sorry, forgot the [PIC]: tag the first time. >------ >Is there a way to save couple of bytes (8 or 10 bytes) to eeprom just >before power outage? > >* I am using MPLAB C18 (the software is in C) >* The unit is working with 220V AC converted to 12V DC then 5V DC. >* Configuration bit is set so power on reset on, brown out detection on, >brown out voltage 4.2, oscillator H4 (10MHz xtal working at 40MHz). > >I looked up the datasheet, according to page 27, I checked the RCON >registers POR bit (that is the only one affected with brown out for some >reason) and saved 8 bytes to eeprom if the POR bit was 1. I did this at >the very first thing in the main() procedure. However, it did not >work. Any ideas? I think you'll need to add hardware to detect an impeding failure and make sure your power supply holds up the Vdd bus long enough to complete your write. You could poll and input or use an interrupt. You might follow the following rough procedure.. you could think of the polling/interrupt as an unpleasant visit or phone call from your doctor. Note that it's possible that power may come back during the shutdown, you may want to check for that so a momentary dip doesn't lock up your instrument. Impeding possible failure detected | Change to low-power mode (change outputs etc to extend up-time) | Write in progress flag to EEPROM | Write data to EEPROM | Clear in progress flag in EEPROM | Go to sleep mode and wait for death The in-progress flag thing may be left out if you design the hardware to always have enough time do the write, but eventually the capacitors will die and you might want it if there is no other error detection. Best regards, Spehro Pefhany --"it's the network..." "The Journey is the reward" speff@interlog.com Info for manufacturers: http://www.trexon.com Embedded software/hardware/analog Info for designers: http://www.speff.com -- http://www.piclist.com#nomail Going offline? Don't AutoReply us! email listserv@mitvma.mit.edu with SET PICList DIGEST in the body