Timer Interrupt help please

General discussion on mikroC for dsPIC30/33 and PIC24.
Post Reply
Author
Message
chapmjw
Posts: 33
Joined: 04 Oct 2004 19:46
Location: Alabama, US

Timer Interrupt help please

#1 Post by chapmjw » 29 May 2006 17:55

Can some one please post an example using the timer interrupt for the 4013. I'm not getting anywhere with the datasheet or help.
thanks
jim

chapmjw
Posts: 33
Joined: 04 Oct 2004 19:46
Location: Alabama, US

Timer Interrupt help please

#2 Post by chapmjw » 30 May 2006 03:18

Here's my crack at the timer interrupt. Just a modification of the Pascal example.

void Timer1Int() org 0x1A
How do we know that the address of this interrupt is 0x1A? I don't see a reference in any documentation.



// timer interrupt
void init()
{
TRISB = 0;
LATB = 255;
ADPCFG= 0XFFFF;
}

void InitTimerInterrupt()
{
IPC0.F12 = 1; // interrupt priority level = 1
IFS0.F3 = 0; // clear TMR1IF
IEC0.F3 = 1; // enable Timer1 interrupts
T1CON.F4 = 0; // timer prescaler bit 4-5 1:1,1:8,1:64,1:256
T1CON.F5 = 1; // timer prescaler bit 4-5 1:1,1:8,1:64,1:256
T1CON.F15 = 1; // Timer On
}

void Timer1Int() org 0x1A
{
IFS0.F3 = 0;
LATB = ~PORTB;
}

int main()
{
init();
InitTimerInterrupt();
while(1) { }
}

User avatar
zristic
mikroElektronika team
Posts: 6608
Joined: 03 Aug 2004 12:59
Contact:

Re: Timer Interrupt help please

#3 Post by zristic » 30 May 2006 08:14

chapmjw wrote:How do we know that the address of this interrupt is 0x1A? I don't see a reference in any documentation.
Image
Image

rolfz
Posts: 30
Joined: 08 Jun 2006 23:40
Location: Switzerland

#4 Post by rolfz » 23 Jun 2006 18:49

Had same problem

Found out that the address to add to the interrupt routine is:

(Vector Number)*2+4, converted in hex

Explanation

Vector table starts at address 4 and each address uses 2 bytes.

KR
Rolfz

Post Reply

Return to “mikroC for dsPIC30/33 and PIC24 General”