简体   繁体   中英

Interrupt-On-Change during execution runtime

I am using Interrupt-On-Change on RC7 of PIC16LF1618. Here is the initialization bit that I use for IOC:

void I_O_C_Initialize (void) {
    INTCONbits.IOCIF = 0;
    IOCCFbits.IOCCF7 = 0;
    INTCONbits.IOCIE = 1;
    IOCCP = 0x80;
}

I am able to wake the PIC from a Power-Down Mode (SLEEP) using a positive trigger on RC7. However, I would like to have this trigger available during execution time as well, as if any positive trigger on RC7 should reset the PIC and go to the first line of the main() function.

Could you please let me know on how to achieve this?

PS: Since the reset needs to happen as quick as possible and is crucial to the execution time, I am unable to add multiple if statements inside the main function to check for the positive trigger on RC7. Hence I am looking for an interrupt option to reset the PIC, even if it is executing a delay or function loops.

Thanks

In most 8-bit PIC devices, and assuming you're using XC8, there is a definition that invokes the required assembly command:

#define RESET() asm("reset")

So, in your interrupt handler, just insert this line of code:

RESET();

The issue has now been resolved. After enabling GIE bit whenever I needed the Interrupt On Change (IOC) during runtime and using the below function, the IOC worked during runtime as well as Power-Down Mode (SLEEP).

void interrupt ISR (void);

void interrupt ISR (void) { 
    if (RC7==1) {
        asm("pagesel foobar");
        asm("goto foobar");
    }
    else
        return;
} 


asm("foobar:");
while (1) {
    IOCCFbits.IOCCF7 = 0;
    INTCONbits.GIE = 1;

    . //Do the calculations here
    . //Here if any Interrupt On Change happens for RC7,
    . //the ISR routine would stop all calculations and
    . //would return to the start of the loop without
    . //resetting any of the registers.

    INTCONbits.GIE = 0;
    IOCCFbits.IOCCF7 = 0;
    SLEEP();
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM