我已经看到一些线程重新调整睡眠模式并使用LPRC从它唤醒。 大多数帖子都说不可能。 只是看看伪代码,并讨论这是否有效? 我没有要测试的硬件。
.... 在睡眠期间,时钟切换到LPRC,主振荡器打开 配置定时器1秒钟中断。
去睡觉 / 等待1秒,1秒后醒来 / 将时钟切换回正常的初级osc ..
这会有用吗?
int main(void)
{
TRISA = 0x0000; //Configure PORTA to be output port
AD1PCFGL=0xffff; //Set all port pin to be digital
EnableWDT(WDT_ENABLE); //Enable Watchdog Timer
ConfigureOscillator();
Timer2_config();
Timer2_Enable();
mPWRMGNT_GotoSleepMode(); //Put the device into Sleep mode
/************ Device Enters Sleep mode and wakes up from sleep upon Watchdog timer time out **********************/
if (Exit_flag)
{
LATA = 0xFFFF; //Output Logic High on PORTA to turn on LED
}
while(1); //end of program
}
void ConfigureOscillator(void)
{
/* Disable Watch Dog Timer */
RCONbits.SWDTEN = 0;
/*
* When clock switch occurs switch to LPRC
* current osc : PRI osc; new osc :LPRC.
* primary oscillator running in sleep mode POSCEN bit enabled.00
* Oscillaotr switch enable.
* Wait till current oscillator is LPRC
*/
__builtin_write_OSCCONH(0x25); /* Set OSCCONH for clock switch */
__builtin_write_OSCCONL(0x05); /* Start clock switching */
while(OSCCONbits.COSC != 0b101);
}
void __attribute__ ((interrupt,no_auto_psv)) _T2Interrupt (void)
{
T2_Clear_Intr_Status_Bit; //clear the interrupt flag
count++;
if (count == 2)
{
Exit_flag=1; // sets the flag every 2 seconds.
count =0;
}
}
void Timer2_config()
{
T2CON = 0x00;
TMR2 = 0x00; // clear timer2 value
PR2 = 0xFFFF; // 1.11 s value
_T2IF = 0;
_T2IE = 1;
_T2IP = 1;
T2CONbits.TSIDL = 0; // continue module operation in idle mode
T2CONbits.TGATE = 0; // Gated time accumulation disabled
T2CONbits.T32 = 0; // Timerx and Timery act as two 16-bit timers
T2CONbits.TCS = 0; // Internal clock (FOSC/2);
T2CONbits.TCKPS = 0; // 1:1 prescalar
T2CONbits.TON = 0;
}
void Timer2_Enable()
{
T2CONbits.TON = 1;
}