RE: C18 interrupt How To
2004/08/23 12:53:58
(permalink)
there is an exampe of using interrupts in the c18 users guide. this is a segment of code i have. i am using both high and low priorities.
this code just shows the low priority.
#pragma code low_vector=0x18 //Low interrupt priority starts at 0x18
void low_interrupt(void)
{
_asm GOTO low_isr _endasm
}
#pragma code
#pragma interrupt low_isr save=PROD //Context Save
void low_isr (void)
{
if(INTCONbits.TMR0IF) //Timer0 interrupt
{
INTCONbits.TMR0IF = 0; // reset overflow bit
do what u need to do.............. }
}
main ....
INTCONbits.GIE = 1; //enable interrupts
RCONbits.IPEN = 1; // turn priority levels on
INTCON2bits.TMR0IP = 0; //set timer0 to low priority
check the pic datasheet for what flags there are. IF are set when somethign overflows, i.e. timer, recieve, transmit, etc. IP are priority level (low and high, if you have both). hope this helps.
erik