Ranbeer Singh
Full Member level 5
- Joined
- Jul 30, 2015
- Messages
- 259
- Helped
- 22
- Reputation
- 44
- Reaction score
- 22
- Trophy points
- 1,298
- Location
- Faridabad India
- Activity points
- 3,266
Hello
I want to use 3 timers(timer0,1,3) of Pic18f4520. In my codes when i enable any one timer ISR function works fine. But when i enable any two/three timers in main function ISR and other codes misbehave.
Codes
I want to use 3 timers(timer0,1,3) of Pic18f4520. In my codes when i enable any one timer ISR function works fine. But when i enable any two/three timers in main function ISR and other codes misbehave.
Codes
Code:
#include <p18f4520.h>
// High priority interrupt vector
void chk_isr(void);
void InitTimer0(void);
void InitTimer1(void);
void InitTimer3(void);
void TMR0_Func(void);
void TMR1_Func(void);
void TMR3_Func(void);
#pragma interrupt chk_isr
void chk_isr(void)
{
if(PIR1bits.TMR1IF) TMR1_Func();
if(PIR2bits.TMR3IF) TMR3_Func();
if(INTCONbits.TMR0IF) TMR0_Func();
}
#pragma code isr = 0x08 // store the below code at address 0x08
void isr(void)
{
_asm
GOTO chk_isr
_endasm
}
#pragma code
void main ()
{
TRISA=0xCF;
PORTA=0x00;
TRISB=0x07;
PORTB=0x00;
TRISC=0x00;
PORTC=0x00;
TRISD=0x00;
PORTD=0x00;
TRISE=0x00;
PORTE=0x00;
PIE1bits.TMR1IE=1;
PIR1bits.TMR1IF=0;
PIE2bits.TMR3IE=1;
PIR2bits.TMR3IF=0;
INTCONbits.TMR0IE=1;
INTCONbits.TMR0IF=0;
INTCONbits.PEIE=1;
INTCONbits.GIE=1;
InitTimer0();
InitTimer1();
InitTimer3();
while(1){}
}
//************************************************************************************
void InitTimer0(){
T0CON = 0x84;
INTCONbits.TMR0IF = 0;
TMR0H = 0xFF; //
TMR0L = 0x5E;
T0CONbits.TMR0ON = 1;
}
void InitTimer1(){
T1CON = 0x19;
PIR1bits.TMR1IF = 0;
TMR1H = 0x3C;
TMR1L = 0xE5;
T1CONbits.TMR1ON = 1;
}
void InitTimer3(){
T3CON = 0x19;
PIR2bits.TMR3IF = 0;
TMR3H = 0x00;
TMR3L = 0xE5;
}
void TMR0_Func()
{
// Functiin codes
}
void TMR1_Func()
{
// Functiin codes
}
void TMR3_Func()
{
// Functiin codes
}