This tip has been extracted from the full-length version, "Finding the Cause of Reset".
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: the PD bit which is set on power-up, cleared when SLEEP is invoked and the TO bit which is cleared if a watchdog time-out occurred, causing 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 that 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 thus, 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.