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.

Clearing interrupt flag

Status
Not open for further replies.

tubos

New Member
I understand when program flow is inside an interrupt routine
it is necessary to clear the appropriate interrupt flag.

Now i have 2 questions about this:
-Is it important if you do this in the beginning or the end of ISR ?
-Could someone explain what happens if you dont clear it?

Heres an example that clears the flag in the end.
Code:
     INT_SERV:
     INCF COUNTER, F

     BTFSS COUNTER, 0    ; light the appropriate LEDs
     BCF PORTB, 4
     BTFSC COUNTER, 0
     BSF PORTB, 4
     BTFSS COUNTER, 1
     BCF PORTB, 5
     BTFSC COUNTER, 1
     BSF PORTB, 5
     BTFSS COUNTER, 2
     ...... other stuff     
     BCF INTCON, INTF    ; clear the appropriate flag
     RETFIE              ; this also set global interrupt enable


Here's another one ex (microchip) that does it in the beginning
Code:
RTCisr 
  BANKSEL TMR1H
  BSF TMR1H, 7 ; Preload for 1 sec overflow
  BCF PIR1, TMR1IF ; Clear interrupt flag
  INCF secs, F ; Increment seconds
  MOVF secs, w
  SUBLW .60
  BTFSS STATUS, Z ; 60 seconds elapsed?
  RETURN ; No, done
  CLRF seconds ; Clear seconds
  INCF mins, f ; Increment minutes
  MOVF mins, w
  ... etc
  RETURN ; Done
 
By clearing the Int. flag you 're-enable' the interrupt vector at 0x0004( 16F). If u don't clear the flag the interrupt won't redirect your code execution after the first time.


If there's a chance that an interrupt can happen while still in the ISR...clear the flag at the end of the ISR. Otherwise it's your choice.
 
Last edited:
By clearing the Int. flag you 're-enable' the interrupt vector at 0x0004( 16F). If u don't clear the flag the interrupt won't redirect your code execution after the first time.

I'm not sure that's worded very well. May I supplement it?

If you don't clear the interrupt flag you'll go right back into the ISR after the return-from-interrupt instruction because the mcu will interpret the interrupt flag as a pending interrupt.
 
Last edited:
Status
Not open for further replies.

Latest threads

Back
Top