Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Assembly Language on PIC 16F872 ( Interrupts)

Status
Not open for further replies.

scdoro

Member level 5
Joined
Jan 12, 2005
Messages
87
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
1,040
Hi,
I have some doubts on programing PIC 16F872 using assembly language.
1) Can a program have more than one interrupts ? If so, may I know how to set priority? so that two interrupt will not clash together ?
2) at the beinging of a program
org 0x000
goto start ;skip over location pointed to by
; interrupt vector
org 0x004
goto iserv
if there are more than one interrupt, do i need to add in other command to the above vector ?
3) can two interrupt happen at the same time ? how to overcome this ?
4) can we call a subroutine ( call function ) in a interrupt service routine ?

Thanks a lot for the help
 

Hi,

there is only one interrupt priority on the PIC16 series only PIC18 series has two interrupt priorities ...

1) your program can have as many interrupts as your PIC supports but you can not set priority and you can also not do anything to prevent a few interrups triggering at the same time.

2) no as this is not supported with PIC16

3) any interrupt can happen at the same time you can not do anything against this

4) yes you can call a function during interrupt but you should try not to do this because it adds another stack level (and PIC16 only have eight levels) and it will also delay your interrupt response. It is a godd idea to keep the interrupt subroutine as short as possible.

To support multiple interrups you will ahve to do an interrupt handler like this (Hi-Tech C):

void interrupt isr(void)
{
if(RCIF)
{
}

if(TMR2IF)
{
}
}

Do not forget to clear the interrupt flag that was causing your interrupt if not done automatically by hardware otherwise you will be stuck inside your interrupt routine forever :)

hope this helps and best regards
 

    scdoro

    Points: 2
    Helpful Answer Positive Rating
1) Can a program have more than one interrupts ? If so, may I know how to set priority? so that two interrupt will not clash together ?

2) at the beinging of a program
org 0x000
goto start ;skip over location pointed to by
; interrupt vector
org 0x004
goto iserv
if there are more than one interrupt, do i need to add in other command to the above vector ?
All interrupts will vector to 0x004. At this point you need to test various flags to see what caused the interrupt and then branch accordingly.


3) can two interrupt happen at the same time ? how to overcome this ?
The global interrupt flag will be cleared during the interrupt vector and re-enabled when you call RETFIE to return. This will prevent any other interrupts from firing, even though their flag may get set. Do not forget to save and restore context of the status, W and PCL registers. Also clear the flag that caused the interrupt before returning else you will go straight back into the ISR.

4) can we call a subroutine ( call function ) in a interrupt service routine ?
You can, but better practice is to set some sort of flag and then handle this from your program's main loop. Remember, the ISR is blocking all other interrupts so it depends on how time critical your code / application is. Some higher level language prevent you from calling a subroutine in the interrupt to ensure you code in a safe way. At the asm level you had better take care of this yourself.
 

    scdoro

    Points: 2
    Helpful Answer Positive Rating
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top