IOC(interrupt on change) not working in MPLAB MCC

Submitted by Megha on

I am new to PIC controller

 

I am using PIC16F18857 for my application, MPLAB X IDE v5.40 , XC8 compiler V2.10 and MPLAB Code configuration(MCC) for my application.

 

I created the project in MPLAB X IDE for PIC16F18857 controller and opened with MCC and set the system clock frequency to 8MHZ , watch dog timer disabled and low voltage programming is enabled.

I configured pin 2 /RA0 as switch input and IOC on negative edge , pin3/PA1 as output LED…

Generated the project:

Checked the MCC generated files:

Interrupt manager file has code :

include "interrupt_manager.h"

include "mcc.h"

void __interrupt() INTERRUPT_InterruptManager (void)
{
// interrupt handler
if(PIE0bits.IOCIE == 1 && PIR0bits.IOCIF == 1)
{
PIN_MANAGER_IOC();
}
else
{
//Unhandled Interrupt
}
}

********************************************************************

pin manager file , where i added the LED toggle macro:

include "pin_manager.h"

void (*IOCAF0_InterruptHandler)(void);

void PIN_MANAGER_Initialize(void)
{
/*
LATx registers
/
LATA = 0x00;
LATB = 0x00;
LATC = 0x00;

/**

TRISx registers

*/

TRISA = 0xFD;

TRISB = 0xFF;

TRISC = 0xFF;

 

/**

ANSELx registers

*/

ANSELC = 0xFF;

ANSELB = 0xFF;

ANSELA = 0xFC;

 

/**

WPUx registers

*/

WPUE = 0x00;

WPUB = 0x00;

WPUA = 0x00;

WPUC = 0x00;

 

/**

ODx registers

*/

ODCONA = 0x00;

ODCONB = 0x00;

ODCONC = 0x00;

 

/**

SLRCONx registers

*/

SLRCONA = 0xFF;

SLRCONB = 0xFF;

SLRCONC = 0xFF;

 

/**

INLVLx registers

*/

INLVLA = 0xFF;

INLVLB = 0xFF;

INLVLC = 0xFF;

INLVLE = 0x00;

 

 

/**

IOCx registers

*/

//interrupt on change for group IOCAF - flag

IOCAFbits.IOCAF0 = 0;

//interrupt on change for group IOCAN - negative

IOCANbits.IOCAN0 = 1;

//interrupt on change for group IOCAP - positive

IOCAPbits.IOCAP0 = 0;

 

 

 

// register default IOC callback functions at runtime; use these methods to register a custom function

IOCAF0_SetInterruptHandler(IOCAF0_DefaultInterruptHandler);

 

// Enable IOCI interrupt

PIE0bits.IOCIE = 1;

}

void PIN_MANAGER_IOC(void)
{
// interrupt on change for pin IOCAF0
if(IOCAFbits.IOCAF0 == 1)
{
IOCAF0_ISR();
}
}

/*
IOCAF0 Interrupt Service Routine
/
void IOCAF0_ISR(void) {

// Add custom IOCAF0 code

 

// Call the interrupt handler for the callback registered at runtime

if(IOCAF0_InterruptHandler)

{

    IOCAF0_InterruptHandler();

}

IOCAFbits.IOCAF0 = 0;

}

/
Allows selecting an interrupt handler for IOCAF0 at application runtime
/
void IOCAF0_SetInterruptHandler(void (
 InterruptHandler)(void)){
IOCAF0_InterruptHandler = InterruptHandler;
}

/*
Default interrupt handler for IOCAF0
/
void IOCAF0_DefaultInterruptHandler(void){
// add your IOCAF0 interrupt custom code
// or set custom function using IOCAF0_SetInterruptHandler()
LED_Toggle();
}

/*
End of File
/

Main application
/
void main(void)
{
// initialize the device
SYSTEM_Initialize();

// When using interrupts, you need to set the Global and Peripheral Interrupt Enable bits

// Use the following macros to:

 

// Enable the Global Interrupts

**INTERRUPT_GlobalInterruptEnable();

**
// Enable the Peripheral Interrupts
INTERRUPT_PeripheralInterruptEnable();

// Disable the Global Interrupts

//INTERRUPT_GlobalInterruptDisable();

 

// Disable the Peripheral Interrupts

//INTERRUPT_PeripheralInterruptDisable();

 

while (1)

{

    // Add your application code

}

}

these are the coding files....

when i press the switch LED is not toggling ...

not getting where is the problem in IOC(interrupt on change)..

please help me to sort out... this is much needed to me..

 

M

Megha

  Joined November 09, 2020      1

Monday at 09:46 PM

MCC configuration on Pin module:

 

this is the interrupt module ...

 

please help me to fix the issue ...

i am stuggling much to fix those...

Sourav Gupta

  Joined February 12, 2018      696

Monday at 02:11 PM

Use an external pull up and check.