13 Eylül 2017 Çarşamba

Interrupt TMR1

Timer interrupt is used to interrupt the code for a given time. I followed the example at http://microchipdeveloper.com/mcu1101:project-10 in PIC18F24K20. It works well.

Proteus: just connect a LED to RA2. We will blink this LED using TMR1 interrupt with a period of 500ms


MCC: select RA2 for output, 1MHz internal OSC and add TMR1 peripheral. clock FOSC/4, scaler 1:2, enable interrupt and synch and write 500ms period.


XC8: enable global and peripheral interrupts. On the ISR routine toggle RA2, this will happen at every 500ms interrupt. that's all.


include "mcc_generated_files/mcc.h"

void myTimerISR(void);


/*
                         Main application
 */
void main(void)
{
    // Initialize the device
    SYSTEM_Initialize();
    
    TMR1_SetInterruptHandler (myTimerISR);     //Define interrupt Handler


    // Enable the Global Interrupts
    INTERRUPT_GlobalInterruptEnable();


    // Enable the Peripheral Interrupts
    INTERRUPT_PeripheralInterruptEnable();


    while (1)
    {
        // Add your application code
    }
}

void myTimerISR(void){
    IO_RA2_Toggle();
}



Hiç yorum yok:

Yorum Gönder