Code: Select all
void go_sleep(void)
{
unsigned char oldTRISB, dummy;
portb = 0;
porta = 0;
oldTRISB = trisb;
trisb = 0xff;
clear_bit(intcon, GIE);
set_bit(intcon, RBIE);
dummy = portb;
clear_bit(intcon, RBIF);
sleep();
nop();
clear_bit(intcon, RBIF);
clear_bit(intcon, RBIE);
set_bit(intcon, GIE);
trisb = oldTRISB;
}