RTCC battery backup w/sleep

Status
Not open for further replies.
Okay, parts are on order. I believe I want to go into idle mode instead of sleep. It looks like I need the following code:
Code:
#define Idle() {__asm__ volatile (pwrsav #1);}

Idle();  //enter idle mode

However how do I look for the switchover in power from AC to the battery?
 
Could I do this:
Code:
int main(void)
 {
    while (1)
    {
        if (PORBbits.RB7 == 0)      // Assume this indicates "No AC"
        {
            /* You may need to set your I/O pins to proper state to reduce current */
             PMD1 = 0xFFFF;
             PMD2 = 0xFFFF;
             PMD3 = 0xFDFF;         // RTCC alive
             _IDLE = 1;
              IDLE();
              if (_IDLE == 0)             // To verify that the processor indeed went to idle
               LATAbits.LATA8  ^= 1; // toggle RA8 after waking up
         }
         
     }
 }

The connect RB7 to the 5V AC. When power goes out, this should go to zero. Correct? That way if for any reason an interupt fires, it would go back into idle mode until power is restored.
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…