Finding the Cause of Reset

This tip has been extracted from the full Finding the Cause of Reset article.

The Microchip baseline and mid-range PIC® MCU devices employ a special feature that lets you establish the cause of a device reset once your program has restarted. This feature uses two bits in the STATUS register, namely the PD bit, which is set on power-up and cleared when SLEEP is invoked; and the TO bit, which is cleared if a watchdog time-out occurred and caused a device wake-up.

Since the content of the STATUS register could be lost before your code can access it, the MPLAB® XC8 C Compiler provides a feature which can automatically copy the STATUS register to a location that can be accessed from C code at a later time. This step takes place at the beginning of the runtime startup code, and so it will be executed shortly after the reset has taken place.

To access the saved content of the STATUS register, your C code should declare and reference the symbol __resetbits (note the two leading underscores). You can also declare and reference the symbols __powerdown and __timeout, which hold copies of the Power-down and Time-out bits, respectively. If required, declare these as follows in your program.

This STATUS register preservation feature is automatically enabled once you access any of the above symbols in your project.

© 2017 Microchip Technology, Inc.
Notice: ARM and Cortex are the registered trademarks of ARM Limited in the EU and other countries.
Information contained on this site regarding device applications and the like is provided only for your convenience and may be superseded by updates. It is your responsibility to ensure that your application meets with your specifications. MICROCHIP MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY KIND WHETHER EXPRESS OR IMPLIED, WRITTEN OR ORAL, STATUTORY OR OTHERWISE, RELATED TO THE INFORMATION, INCLUDING BUT NOT LIMITED TO ITS CONDITION, QUALITY, PERFORMANCE, MERCHANTABILITY OR FITNESS FOR PURPOSE. Microchip disclaims all liability arising from this information and its use. Use of Microchip devices in life support and/or safety applications is entirely at the buyer's risk, and the buyer agrees to defend, indemnify and hold harmless Microchip from any and all damages, claims, suits, or expenses resulting from such use. No licenses are conveyed, implicitly or otherwise, under any Microchip intellectual property rights.