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.

Pic16F877A interrupt

Status
Not open for further replies.
Pommie said:
No need. The retfie sets the GIE bit automatically.

Mike.

Hi, sorry to 'interrupt' here. I program my uC 877A with several interrupts such as ADC and RB0. If there's an interrupt in an interrupt, is it necessary to set the INTCON GIE again. As the GIE being reset, the 2nd interrupt cannot occur? Correct me if wrong. But if i try to set the GIE back, the program will stuck there as setting GIE will route the program back to 0x04 again. I'm burning up with my PIC programming...
 
Last edited:
It's not a good idea to set the GIE bit in the ISR unless you are able to double buffer the context saving code. If you have an ISR that may take a long time then set a flag in your ISR and process it in your main code. Keep all interrupts as short (time wise) as practicable. Another problem with recurrent interrupts is the lack of stack space on the pic chips.

If you are asking "will the 2nd interrupt get lost" then the answer is No, the relevant interrupt flag gets set and as soon as the retfie sets the GIE bit then the interrupt will get serviced.

Mike.
 
Interrupt within an interrupt with 16F PIC is more difficult to code generally because all interrupts vectors to address 0x4.

This then involves two actions: saving context and testing & jump to correct handling routine. If one tests for the correct interrupt first, one would risk changing bits in STATUS or W registers which causes disaster later. So saving context has to be done first.

While the proper return address is taken care of by the PIC hardware stack, user must implement some form of software stack to save the context of registers otherwise the saving context action by the second interrupt will mess up the saved value of the first interrupt.

In case of PIC, it is so much simpler just to allow one interrupt to finish before processing the second interrupt. Multiple interrupts is common and easy to code using a software stack along with PUSH and POP instructions in other types of uP/uC.
 
Sorry for such a nonsense!!

Pommie said:
No need. The retfie sets the GIE bit automatically.

Mike.

I have no excuses. Right now I am working in two interupts combined to each other and I know that I DON'T NEED TO SET GIE. The hardwar does it after a RETFIE instruction.

Trying to post immediately is not good.

Sorry for the OP being mislead by my reply and gracias Pommie for showing my mistake.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top