PIC16F1827 stuck in any_Timer Interrupt

General discussion on mikroC PRO for PIC.
Post Reply
Author
Message
HyperUniverse
Posts: 282
Joined: 17 Jun 2009 10:42

PIC16F1827 stuck in any_Timer Interrupt

#1 Post by HyperUniverse » 10 Nov 2023 14:47

Hi

I'm stuck in Timer Interrupt Routine using a PIC16F1827;

Very simple LED ON, LED OFF, absolutely nothing else in the program

Code: Select all

#define LED LatB.F3
char LED_cnt = 0 ;

   /* Timer0
      Prescaler 1:256; TMR0 Preload = 61; Actual Interrupt Time : 49.92 ms  */
  OPTION_REG	 = 0x87;
  TMR0		 = 61;
  INTCON.TMR0IE = 1;
  INTCON.TMR0IF = 0;
   INTCON.PEIE = 1 ;
   INTCON.GIE = 1 ;
  
  while(1) {
      asm CLRWDT;
      if(LED_cnt >= 20) {              // about 1_sec_ON, then 1_sec_OFF
         LED =~ LED ;
           LED_cnt = 0 ;
      }
 }     

Code: Select all

void Interrupt() iv 0x0004 ics ICS_AUTO {
  if (TMR0IF_bit){
    TMR0IF_bit = 0;
    TMR0 = 61;
    
    LED_cnt ++ ;
 //   LED = 1 ;   // if I uncomment this line, I can see the LED comming ON
                  //   so that means the program reaches this line, but then the
                  //   PIC resets itself and starts all over again
  }
}

No matter which timer I'm using is doing it the same.

Has anybody got any idea?

Thanks.

hexreader
Posts: 1784
Joined: 27 Jun 2010 12:07
Location: England

Re: PIC16F1827 stuck in any_Timer Interrupt

#2 Post by hexreader » 10 Nov 2023 16:45

You have not set port B to output

You have not configured OSCCON.

Working, tested project attached
Attachments
forum.zip
(17.96 KiB) Downloaded 25 times
Start every day with a smile...... (get it over with) :)

HyperUniverse
Posts: 282
Joined: 17 Jun 2009 10:42

Re: PIC16F1827 stuck in any_Timer Interrupt

#3 Post by HyperUniverse » 10 Nov 2023 18:01

thanks for reply hexreader
working fine now.

I was afraid the PIC might be damaged as I got it from ebay,
and instead of looking better at my code, I was stuck into thinking to contact the seller for a replacement

Post Reply

Return to “mikroC PRO for PIC General”