I tried to wake up a PIC (16F88) from sleep using Timer1 Interrupt with external crystal. But it doesn't work. I tested it using watch dog timer and it works. But I want to use Timer1 Interrupt. It doesn't wake up. My code is here. I used PIC 16F88, (checked also 12F683) and 4MHz Crystal.
unsigned short cnt;
void interrupt() {
if (TMR1IF_bit) {
T1CON.TMR1ON = 0;
cnt++;
TMR1H = 0x00;
TMR1L = 0x00;
T1CON.TMR1ON = 1;
TMR1IF_bit = 0; // clear TMR0IF
}
}
void main() {
ANSEL = 0; // Configure AN pins as digital
TRISA = 0x00;
PORTA = 0x00;
TRISB = 0;
PORTB = 0x00;
cnt=0;
T1CON = 0b10110101; // Timer1 settings, No Sync with internal oscillator
TMR1IF_bit = 0; // clear TMR1IF
T1CON.TMR1ON = 0;
TMR1H = 0x00; // Initialize Timer1 values again
TMR1L = 0x00;
T1CON.TMR1ON = 1;
TMR1IE_bit = 1; // enable Timer1 interrupt
INTCON = 0xC0; // Set GIE, PEIE
//OSCCON.IDLEN = 0;
do {
asm SLEEP
asm nop
//asm nop
if (cnt>=1) {
PORTB=~PORTB;
cnt=0;
}
} while (1);
}
I tested it changing T1CON as 0b00110111. Doesn't works. What is wrong in my codes? Please help me. Thanks.