14 Eylül 2017 Perşembe

Interrupt TMR0

We can use TMR0 timer interrupt in a different way. We will add interrupt code inside tmr0.c file instead of main.c as it was in TMR1 example.

Proteus: the same circuit with a LED connected to RA2. We will toggle the LED at 250ms using TMR0 interrupt.


MCC: add TMR1 timer. enable interrupt, select FOSC/4, 16bit and 250ms


XC8: we will add the code to toggle RA2 inside tmr0.c we have to add "mcc.h" to include files otherwise IO_RA2_Toggle() will give error. So, this was 3rd method to blink a LED using timers interrupt and overflows.


#include <xc.h>
#include "tmr0.h"
#include "mcc.h"

void TMR0_ISR(void)
{

    // clear the TMR0 interrupt flag
    INTCONbits.TMR0IF = 0;

    // reload TMR0
    // Write to the Timer0 register
    TMR0H = timer0ReloadVal >> 8;
    TMR0L = (uint8_t) timer0ReloadVal;

    if(TMR0_InterruptHandler)
    {
        TMR0_InterruptHandler();
    }

    // add your TMR0 interrupt custom code
    IO_RA2_Toggle();
}




Hiç yorum yok:

Yorum Gönder