Hi.. I came across several ways of writing interrupt and i need some help on it..
Below are some of the interrupts i got from C18 C Compiler User Guide.
1)
#pragma interruptlow low_interrupt_service_routine save=PROD
void low_interrupt_service_routine()
{
}
2)
#pragma interrupt high_interrupt_service_routine save=section("mydata")
void high_interrupt_service_routine()
{
}
3)
#pragma interrupt high_interrupt_service_routine save=section(".tmpdata")
void high_interrupt_service_routine()
{
}
On one website, I came across these
And in the same website i found this
Hmm.. after reading about the interrupt, i still dun really get the reason for the extra "save= bla bla bla" after the ISR.. I also don't understand fast interrupt or slow interrupt..
Another thing is when should I use high interrupt and when to use low interrupt..? Lets say, I want to just write an interrupt for Timer2 to read from ADC every 125us, do I need a high interrupt or low interrupt..?
And also, can i leave out the "save=" part when declare the ISR..? Umm.. i am assuming that "#pragma interrupt" is to declare the ISR right..?
Below are some of the interrupts i got from C18 C Compiler User Guide.
1)
#pragma interruptlow low_interrupt_service_routine save=PROD
void low_interrupt_service_routine()
{
}
2)
#pragma interrupt high_interrupt_service_routine save=section("mydata")
void high_interrupt_service_routine()
{
}
3)
#pragma interrupt high_interrupt_service_routine save=section(".tmpdata")
void high_interrupt_service_routine()
{
}
On one website, I came across these
Code:
/**********************************************************************
* General interrupt vector. Do not modify.
**********************************************************************/
#pragma code IT_vector_low=0x18
void Interrupt_low_vec(void)
{
_asm goto InterruptVectorL _endasm
}
#pragma code
#pragma code IT_vector_high=0x08
void Interrupt_high_vec(void)
{
_asm goto InterruptVectorH _endasm
}
#pragma code
/**********************************************************************
* General ISR router. Complete the function core with the if or switch
* case you need to jump to the function dedicated to the occuring IT.
**********************************************************************/
#pragma code _INTERRUPT_VECTORL = 0x003000
#pragma interruptlow InterruptVectorL save=section(".tmpdata"), PROD
void InterruptVectorL(void)
{
EnterISR();
if (INTCONbits.TMR0IF == 1)
AddOneTick();
/*Here is the next interrupts you want to manage */
/*if (INTCONbits.RBIF == 1) */
/* MyOwnISR(); */
LeaveISR();
}
#pragma code
And in the same website i found this
Code:
Here is the "fast interrupt" function :
/* BE CARREFULL : ONLY BSR, WREG AND STATUS REGISTERS ARE SAVED */
/* DO NOT CALL ANY FUNCTION AND USE PLEASE VERY SIMPLE CODE LIKE */
/* VARIABLE OR FLAG SETTINGS. CHECK THE ASM CODE PRODUCED BY C18 */
/* IN THE LST FILE. */
#pragma code _INTERRUPT_VECTORH = 0x003300
#pragma interrupt InterruptVectorH
void InterruptVectorH(void)
{
if (INTCONbits.INT0IF == 1)
INTCONbits.INT0IF = 0;
}
#pragma code
The external interrupts INT0 (RB0 pin), INT1 (RB1 pin) and INT2 (RB2 pin) are by default in fast interrupt mode so when an interrupt occurs the current code processing is stopped and the InterruptVectorH() is executed.
Hmm.. after reading about the interrupt, i still dun really get the reason for the extra "save= bla bla bla" after the ISR.. I also don't understand fast interrupt or slow interrupt..
Another thing is when should I use high interrupt and when to use low interrupt..? Lets say, I want to just write an interrupt for Timer2 to read from ADC every 125us, do I need a high interrupt or low interrupt..?
And also, can i leave out the "save=" part when declare the ISR..? Umm.. i am assuming that "#pragma interrupt" is to declare the ISR right..?