-2
\$\begingroup\$

void Timer1Init(void)

_T1IP = 4; // this is the default value anyway
TMR1 = 0; // clear the timer
PR1 =0x0139 ;
T1CON = 0x8030;
_T1IF = 0;
 _T1IE = 1;

void attribute((interrupt, no_auto_psv)) _T1Interrupt(void)

 LATAbits.LATA0 = ~LATAbits.LATA0;  //Toggle output to LED
_T1IF = 0;

void Timer2Init(void)

_T2IP = 4; // this is the default value anyway
TMR2 = 0; // clear the timer
PR2 = 0x1E85;
T2CON = 0x8030;
_T2IF = 0;

void attribute((interrupt, no_auto_psv)) _T2Interrupt(void)

 LATAbits.LATA1 = ~LATAbits.LATA1 ;
 DELAY_MS (6000);
_T2IF = 0;

int main(void)

    TRISAbits.TRISA0 = 0; 
TRISAbits.TRISA1 = 0;
ANSELA = 0x0000;
_RCDIV=0;

Timer1Init();
Timer2Init();
  while (1)  {}

above written program is not working correctly i have given a delay in timer 2 interrupt routine that means there should be delay of 6s for led to blink connected to A1 pin and its working but the problem is that there is also a delay happening while blinking the led connected to pin A0 can anybody help me to tell whats wrong here ?

\$\endgroup\$
  • \$\begingroup\$ Edit your text so we can see the code please. \$\endgroup\$ – Oldfart Mar 23 '18 at 7:40
  • \$\begingroup\$ sorry i done it \$\endgroup\$ – chamanpreet singh Mar 23 '18 at 7:48
  • \$\begingroup\$ Code is still unreadable. There is a code tag button on the editor toolbar. Use that, remove blank lines, indent properly and add comments. For the text of your post please use capital letters and punctuation. Read the post carefully before pressing the "Post Your Question" button. Your compiler won't let you away with it. Why should we? \$\endgroup\$ – Transistor Mar 23 '18 at 7:48
  • \$\begingroup\$ Code formatting is still a mess after your edit. -1. \$\endgroup\$ – Transistor Mar 23 '18 at 10:44
0
\$\begingroup\$

You have a delay in your interrupt routine - this stops any further interrupts (so stopping the other LED from changing state) until it has expired. Interrupt routines should execute as fast as possible and certainly should never* contain delays.

*never say never, but it would be a very unusual application that did

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.