Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

MikroEleKronika Timer 0 Problem

Status
Not open for further replies.

wuchy143

Member
Hi All,

I'm trying to get my timer 0 interrupt to go in Mikro C Pro. I can't seem to get it going. Even with their examples. I looked over the SFR's and am pretty sure they're right. I'm programming a PIC18F46J50. Any ideas?

Code:
void INIT(void);

unsigned int count = 0;
unsigned int LED_COUNT = 10;


void interrupt(){
   if(INTCON.TMR0IF)
   {
   count = count + 1;
   INTCON.TMR0IF = 0;
   }
}

void main()
{
ADCON1 |= 0x0F;                    // Configure AN pins as digital
CM1CON1 |= 7;         // Disable comparators


RCON.IPEN      = 1;               //enabling priotity level on interrupts
INTCON2.TMR0IP = 1;               //high priority level
INTCON.GIE     = 1;               //global interrupt enable
INTCON.PEIE    = 1;               //disable all peripheral interrupts

T0CON.T08BIT   = 1;              //Timer0 is a 8 bit counter
T0CON.T0CS     = 0;              //increments w/ the internal clock
T0CON.PSA      = 0;              //prescalar assigned/enabled
T0CON.T0PS0    = 1;              //Assign prescalar
T0CON.T0PS1    = 1;
T0CON.T0PS2    = 0;
INTCON.TMR0IE  = 1;              //enabling TMR0 interrupt on overflow
INTCON.TMR0IF = 0;
T0CON.TMR0ON   = 1;              //Timer0 is "ON"


     while(LED_COUNT > 1)
     {
       INIT();
     }

     while(1)
     {
     Delay_ms(1);
     }


}

void INIT(void)
{

TRISD         = 0x00;
PORTD         = 0x04;
Delay_ms(100);


PORTD.RD2 = !PORTD.RD2;
Delay_ms(100);
LED_COUNT = LED_COUNT - 1;

}
 
What makes you think it's not working? You code looks ok you are setting GIE and TMR0IE, and your int looks ok it is detecting and clearing TMR0IF.

But the code doesn't do anything.
 
sorry my mistake. I wasn't aware that Mikroelekronika's simulator doesn't upadate timers. I programmed my chip and I"m in fact counting. Sorry to bother. I guess I"m just spoiled with Microchips simulator.

-mike
 
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top