• AVR Freaks

LockedC18 interrupt How To

Author
Guest
Super Member
  • Total Posts : 80503
  • Reward points : 0
  • Joined: 2003/01/01 00:00:00
  • Location: 0
  • Status: online
2004/08/23 11:01:00 (permalink)
0

C18 interrupt How To

Hi all,

I am a little confused about how to create an interrupt routine in "C'. Does anybody have a sample code of it for my start point.

I need it to display a timer count running in the background using timer0.

thanks in advance

Jsantos

aspforum.mchp.guest
#1

3 Replies Related Threads

    Guest
    Super Member
    • Total Posts : 80503
    • Reward points : 0
    • Joined: 2003/01/01 00:00:00
    • Location: 0
    • Status: online
    RE: C18 interrupt How To 2004/08/23 12:49:01 (permalink)
    0
    Here is a sample code for you.
    Regards,
    Thomas

    //---------------------------------------------------------------------
    // High priority interrupt routines
    //---------------------------------------------------------------------
    #pragma interrupt high_isr save=section(".tmpdata"),PROD,section("MATH_DATA")
    void high_isr(void)
    {
    unsigned int Period;

    if (INTCONbits.TMR0IF && INTCONbits.TMR0IE) // TMR0 Interrupt
    {
    INTCONbits.TMR0IF = 0; // clear flag
    Period = TMR0_Timer_Period; // Interrupt every 1ms
    TMR0H = (Period >> 8); // Write low byte to Timer0
    TMR0L = Period; // Write high byte to Timer0

    }

    }

    //---------------------------------------------------------------------
    // Low priority interrupt routines
    //---------------------------------------------------------------------
    #pragma interruptlow low_isr save=section(".tmpdata"),PROD,section("MATH_DATA")
    void low_isr(void)
    {
    Nop();
    }

    //---------------------------------------------------------------------
    // High priority interrupt vector
    //---------------------------------------------------------------------
    #pragma code high_vector=0x08
    void high_interrupt(void)
    {
    _asm GOTO high_isr _endasm
    }
    #pragma code /* return to the default code section */
    //---------------------------------------------------------------------
    // Low priority interrupt vector
    //---------------------------------------------------------------------
    #pragma code low_vector=0x18
    void low_interrupt (void)
    {
    _asm GOTO low_isr _endasm
    }
    #pragma code
    #2
    Guest
    Super Member
    • Total Posts : 80503
    • Reward points : 0
    • Joined: 2003/01/01 00:00:00
    • Location: 0
    • Status: online
    RE: C18 interrupt How To 2004/08/23 12:53:58 (permalink)
    0
    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
    #3
    Guest
    Super Member
    • Total Posts : 80503
    • Reward points : 0
    • Joined: 2003/01/01 00:00:00
    • Location: 0
    • Status: online
    RE: C18 interrupt How To 2004/08/23 13:32:00 (permalink)
    0
    thanks guys .

    Jsantos

    aspforum.mchp.guest
    #4
    Jump to:
    © 2021 APG vNext Commercial Version 4.5