Wake up a PIC from sleep using Timer1 Interrupt

General discussion on mikroC.
Post Reply
Author
Message
AHemantha
Posts: 2
Joined: 28 Jul 2017 06:04

Wake up a PIC from sleep using Timer1 Interrupt

#1 Post by AHemantha » 28 Jul 2017 07:32

Hi,
I tried to wake up a PIC (16F88) from sleep using Timer1 Interrupt. 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 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 checked it changing T1CON as 0b00110111. No success. What is wrong in my codes?
Please help me.

Thanks.

AHemantha
Posts: 2
Joined: 28 Jul 2017 06:04

Re: Wake up a PIC from sleep using Timer1 Interrupt

#2 Post by AHemantha » 28 Jul 2017 16:33

I understood what the error is. T1OSCEN bit of T1CON shold set. T1OSCEN=1.

User avatar
dusan.poluga
mikroElektronika team
Posts: 780
Joined: 02 Feb 2017 14:21

Re: Wake up a PIC from sleep using Timer1 Interrupt

#3 Post by dusan.poluga » 28 Jul 2017 17:16

Hi,

I am glad you could fix it.

Best Regards,
Dusan Poluga.

Post Reply

Return to “mikroC General”