7.2.5 When using a 16-bit device, an unexpected Reset occurred. How do I determine what caused it?

Some things to consider:

  • To determine a Reset source, check the RCON register.
  • Handle traps/interrupts in an Interrupt Service Routine (ISR). You should include trap.c style code, i.e.,
    void __attribute__((__interrupt__)) _OscillatorFail(void);
            :
    void __attribute__((__interrupt__)) _AltOscillatorFail(void);
            :
    void __attribute__((__interrupt__)) _OscillatorFail(void)
        {
            INTCON1bits.OSCFAIL = 0;        //Clear the trap flag
            while (1);
        }
            :
        void __attribute__((__interrupt__)) _AltOscillatorFail(void)
        {
            INTCON1bits.OSCFAIL = 0;
            while (1);
        }
        :
  • Use ASSERTs. For example:
    ASSERT
          (IPL==7)