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.


Well, the reason why it doesn't work is the value you have chosen on both your attempts for the T1CON register.

T1CON = 0b10110101;
T1CON = 0b00110111;

enter image description here

The problem is with the T1OSCEN bit, where it is always set to '0'. The T1OSCEN lets you enable or disable the oscillator that the Timer1 is using when you want it to work on an external crystal.

If the oscillator is disabled, like in your case, the Timer1 cannot work on the external crystal.

Check also the Timer1 block diagram, where it will be clear:

enter image description here

| improve this answer | |
  • \$\begingroup\$ I set T1CON as you said. It works. Many thanks Nickagian. \$\endgroup\$ – PLAA Hemantha Jul 28 '17 at 14:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.