1

我想将 PIC24F32KA302 配置为进入休眠模式并通过 RTC 中断唤醒。但是,醒来后,我的程序又从头开始运行。数据表中提到: - 如果为中断分配的优先级小于或等于当前 CPU 优先级,则器件将唤醒并从启动休眠模式的 PWRSAV 指令之后的指令继续执行代码。- 如果为中断源分配的优先级大于当前的 CPU 优先级,设备将被唤醒并开始 CPU 异常处理。代码执行将从 ISR 的第一条指令开始继续。我尝试了两种配置,但结果是一样的。我的代码如下:

int main(void) {
SYS_Init();
while(1){
    __delay_ms(400);
    Sleep();
}
return 0;}

void __attribute__ ( (interrupt, no_auto_psv) )  _RTCCInterrupt(void) {
IFS3bits.RTCIF = 0;
//To do:
Total_Pulse += TMR1;
TMR1 = 0;
LED = ~LED;}

void InterruptPriority_Init(void) {
INTCON1bits.NSTDIS = 1;
INTCON2bits.ALTIVT = 0;
SRbits.IPL = 1;
IPC15bits.RTCIP = 6;//6
_U2RXIP = 5;
_T1IP = 4;
_U1RXIP = 2;
_HLVDIP = 3;}

函数 SYS_Init() 初始化中断、RTC 和其他外围模块。此函数始终在设备从睡眠模式唤醒后运行。你对我有什么想法或建议吗?谢谢

4

1 回答 1

0

很可能是发生某种错误导致您的设备重置。

您是否添加了陷阱例程?如果没有,请添加此代码并查看您是否进入其中一个陷阱。

还要确保您的电路中没有任何功率下降并且您的复位引脚没有受到某种噪声,您可以在复位引脚和 GND 之间添加一个 100nF 电容器(当然保持上拉)。

/******************************************************************************/
/* Files to Include                                                           */
/******************************************************************************/

/* Device header file */
#if defined(__XC16__)
    #include <xc.h>
#elif defined(__C30__)
    #if defined(__PIC24E__)
        #include <p24Exxxx.h>
    #elif defined (__PIC24F__)||defined (__PIC24FK__)
    #include <p24Fxxxx.h>
    #elif defined(__PIC24H__)
    #include <p24Hxxxx.h>
    #endif
#endif

#include <stdint.h>        /* Includes uint16_t definition */
#include <stdbool.h>       /* Includes true/false definition */

/******************************************************************************/
/* Trap Function Prototypes                                                   */
/******************************************************************************/

/* <Other function prototypes for debugging trap code may be inserted here>   */

/* Use if INTCON2 ALTIVT=1 */
void __attribute__((interrupt,no_auto_psv)) _OscillatorFail(void);
void __attribute__((interrupt,no_auto_psv)) _AddressError(void);
void __attribute__((interrupt,no_auto_psv)) _StackError(void);
void __attribute__((interrupt,no_auto_psv)) _MathError(void);

#if defined(__PIC24F__)||defined(__PIC24H__)

/* Use if INTCON2 ALTIVT=0 */
void __attribute__((interrupt,no_auto_psv)) _AltOscillatorFail(void);
void __attribute__((interrupt,no_auto_psv)) _AltAddressError(void);
void __attribute__((interrupt,no_auto_psv)) _AltStackError(void);
void __attribute__((interrupt,no_auto_psv)) _AltMathError(void);

#endif

/* Default interrupt handler */
void __attribute__((interrupt,no_auto_psv)) _DefaultInterrupt(void);

#if defined(__PIC24E__)

/* These are additional traps in the 24E family.  Refer to the PIC24E
migration guide.  There are no Alternate Vectors in the 24E family. */
void __attribute__((interrupt,no_auto_psv)) _HardTrapError(void);
void __attribute__((interrupt,no_auto_psv)) _DMACError(void);
void __attribute__((interrupt,no_auto_psv)) _SoftTrapError(void);

#endif

/******************************************************************************/
/* Trap Handling                                                              */
/*                                                                            */
/* These trap routines simply ensure that the device continuously loops       */
/* within each routine.  Users who actually experience one of these traps     */
/* can add code to handle the error.  Some basic examples for trap code,      */
/* including assembly routines that process trap sources, are available at    */
/* www.microchip.com/codeexamples                                             */
/******************************************************************************/

/* Primary (non-alternate) address error trap function declarations */
void __attribute__((interrupt,no_auto_psv)) _OscillatorFail(void)
{
        INTCON1bits.OSCFAIL = 0;        /* Clear the trap flag */
        while(1);
}

void __attribute__((interrupt,no_auto_psv)) _AddressError(void)
{
        INTCON1bits.ADDRERR = 0;        /* Clear the trap flag */
        while (1);
}
void __attribute__((interrupt,no_auto_psv)) _StackError(void)
{
        INTCON1bits.STKERR = 0;         /* Clear the trap flag */
        while (1);
}

void __attribute__((interrupt,no_auto_psv)) _MathError(void)
{
        INTCON1bits.MATHERR = 0;        /* Clear the trap flag */
        while (1);
}

#if defined(__PIC24F__)||defined(__PIC24H__)

/* Alternate address error trap function declarations */
void __attribute__((interrupt,no_auto_psv)) _AltOscillatorFail(void)
{
        INTCON1bits.OSCFAIL = 0;        /* Clear the trap flag */
        while (1);
}

void __attribute__((interrupt,no_auto_psv)) _AltAddressError(void)
{
        INTCON1bits.ADDRERR = 0;        /* Clear the trap flag */
        while (1);
}

void __attribute__((interrupt,no_auto_psv)) _AltStackError(void)
{
        INTCON1bits.STKERR = 0;         /* Clear the trap flag */
        while (1);
}

void __attribute__((interrupt,no_auto_psv)) _AltMathError(void)
{
        INTCON1bits.MATHERR = 0;        /* Clear the trap flag */
        while (1);
}

#endif

/******************************************************************************/
/* Default Interrupt Handler                                                  */
/*                                                                            */
/* This executes when an interrupt occurs for an interrupt source with an     */
/* improperly defined or undefined interrupt handling routine.                */
/******************************************************************************/
void __attribute__((interrupt,no_auto_psv)) _DefaultInterrupt(void)
{
        while(1);
}

#if defined(__PIC24E__)

/* These traps are new to the PIC24E family.  Refer to the device Interrupt
chapter of the FRM to understand trap priority. */
void __attribute__((interrupt,no_auto_psv)) _HardTrapError(void)
{
    while(1);
}
void __attribute__((interrupt,no_auto_psv)) _DMACError(void)
{
    while(1);
}
void __attribute__((interrupt,no_auto_psv)) _SoftTrapError(void)
{
    while(1);
}

#endif
于 2016-09-23T03:33:37.543 回答