13 Eylül 2017 Çarşamba

Interrupt On Change

I followed the example at microchip development site: http://microchipdeveloper.com/mcu1101:project-9 but LED was blinking instead of toggling the the state at SW change. Finally I found the answer at http://www.microchip.com/forums/m289430.aspx I had to read the port. "A mismatch condition will continue to set this bit. Reading PORTB will end the mismatch condition and allow the bit to be cleared. " DONT FORGET. 

So Proteus part is simple, state change of RB5 will toggle the LED connected to RA0. RB4,5,6,7 ports can be used for on change interrupt in PIC18F24K20. It may be different for different models.



I was thinking that MCC is not working and decided to continue without MCC but finally I fixed the problem.  in MCC: select RB5 as input, RA0 as output. Check IOC for "any" and select internal 1MHz osc. that's all you need. Interrupt module select RBI enabled.



Code is quiete easy with MCC. Just enable Global and peripheral interrupts at main.c by removing comments.

    // Enable the Global Interrupts
    INTERRUPT_GlobalInterruptEnable();


    // Enable the Peripheral Interrupts
    INTERRUPT_PeripheralInterruptEnable();

nothing in while loop
    while (1)
    {
        // Add your application code
    }

in interrupt_manager.c you can add what you want once interrupt is caught. I toggle the LED, read the port and  reset RBIF Port Change Interrupt Flag Bit.

void interrupt INTERRUPT_InterruptManager (void)
{
    // interrupt handler
    if(INTCONbits.RBIE == 1 && INTCONbits.RBIF == 1)
    {
        PIN_MANAGER_IOC();
        IO_RA0_Toggle();
        IO_RB5_GetValue();
        INTCONbits.RBIF=0;
    }
    else
    {
        //Unhandled Interrupt
    }
}

download the example

1 yorum:

  1. Learning Pic Programing With Xc8 Compiler: Interrupt On Change >>>>> Download Now

    >>>>> Download Full

    Learning Pic Programing With Xc8 Compiler: Interrupt On Change >>>>> Download LINK

    >>>>> Download Now

    Learning Pic Programing With Xc8 Compiler: Interrupt On Change >>>>> Download Full

    >>>>> Download LINK Fa

    YanıtlaSil