How can I use the TO and PD bits to determine the cause of reset on PIC® devices?

Some PIC® devices have Timeout (TO) and Power Down (PD) bits in the STATUS register that can be used to determine the cause of a reset. However, these bits are quickly overwritten by the runtime startup code that is executed before main is executed.

With MPLAB® XC8, the --RUNTIME suboption "resetbits" can be used to preserve these bits, and the entire STATUS register, in variables that can be examined later in your program. This option can be specified in MPLAB X IDE > Project Properties > XC8 Linker category > Runtime drop-down menu > Check / Uncheck the Backup reset condition flags (This field is not available for all the devices).

The state of these bits can be examined after recovering from a Reset condition to determine the cause of the Reset.

The entire STATUS register is saved to an assembly variable __resetbits. This variable can be accessed from C code using the declaration:

The compiler defines the assembly symbols __powerdown and __timeout to represent the bit address of the PD and TO bits within the STATUS register and can be used if required.

For example:

Make sure that the Backup reset condition flags option is selected under MPLAB X Project Properties > XC8 Linker > Runtime (Some devices do not have this option selectable).

For more details, refer to the “Status Register Preservation” section in the Compiler Manual.

© 2024 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.