# PIC24 and INTERRUPT HANDLER

**URL:** <https://forums.freertos.org/t/pic24-and-interrupt-handler/4667>\
**Category:** Kernel\
**Created:** [July 15, 2014, 6:41am UTC](https://forums.freertos.org/t/pic24-and-interrupt-handler/4667 "2014-07-15T06:41:29Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [July 15, 2014, 6:41am UTC](https://forums.freertos.org/t/pic24-and-interrupt-handler/4667/1 "2014-07-15T06:41:29Z")

</div>

**[fabrice48](https://sourceforge.net/u/fabrice48/)** wrote on [Tuesday, July 15, 2014](https://sourceforge.net/p/freertos/discussion/382005/thread/cc3a289f/#e85e):

Hello,

i have a doubt about the interrupt handler on pic24 :  
the official document explain this,

Interrupt can be written in C exactly as described in the compiler.  
Then it was discussed about TWO interrupt handler, C method and ASM method.

readind the manual several time but i don’t understand if i can use C or if i have to use ASM ?

here an example about the Scondary UART Rx Interrupt.  
Can i use this code ? is it correct ?

typedef struct  
{  
unsigned char screen\_pos;  
char\* screen\_mess;  
} lcd\_data;

lcd\_data info\_serie;

void **attribute** ((interrupt, no\_auto\_psv)) \_U2RXInterrupt(void)  
{  
IFS1bits.U2RXIF = 0;  
while( DataRdyUART2())  
{  
message[0] = ReadUART2();  
WriteUART2( message[0] +1 );  
info\_serie.screen\_mess = message;  
info\_serie.screen\_pos = 10;  
xQueueSendToBackFromISR(xQueue\_lcd, &info\_serie,0);

```
  } 

```

}

thank you for help.

fabrice

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [July 15, 2014, 2:02pm UTC](https://forums.freertos.org/t/pic24-and-interrupt-handler/4667/2 "2014-07-15T14:02:36Z")

</div>

**[davedoors](https://sourceforge.net/u/davedoors/)** wrote on [Tuesday, July 15, 2014](https://sourceforge.net/p/freertos/discussion/382005/thread/cc3a289f/#a6b9):

There are two interrupt handlers defined in the PIC24 demo for you to copy (in this file [http://sourceforge.net/p/freertos/code/HEAD/tree/trunk/FreeRTOS/Demo/PIC24\_MPLAB/serial/serial.c](http://sourceforge.net/p/freertos/code/HEAD/tree/trunk/FreeRTOS/Demo/PIC24_MPLAB/serial/serial.c)) and this is what the documentation page for the PIC24 port says:

“Interrupt service routines that cannot cause a context switch have no special requirements and can be written as per the compiler documentation.  
Interrupt service routines that can cause a context switch must execute with priority portKERNEL\_INTERRUPT\_PRIORITY, and only call taskYIELD() at the very end of the service routine after the interrupt source has been cleared. See the file serial.c included in the demo application for an example.”

no mention of assembly code, I don’t know what it is you are reading.

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [July 15, 2014, 2:35pm UTC](https://forums.freertos.org/t/pic24-and-interrupt-handler/4667/3 "2014-07-15T14:35:12Z")

</div>

**[fabrice48](https://sourceforge.net/u/fabrice48/)** wrote on [Tuesday, July 15, 2014](https://sourceforge.net/p/freertos/discussion/382005/thread/cc3a289f/#1426):

Hello Dave,  
my document is the one bought on official freertos website, it’s page 89.  
as i said, i just have a ‘doubt’  
so if the interrupt does not cause a context switch AND if it canoot be itself interrupted i can use the C handler.  
i just began with FreeRtos.

the assembly kind is discussed a the very end of this page.  
my document is the one for PIC32.

thank you

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [July 15, 2014, 2:41pm UTC](https://forums.freertos.org/t/pic24-and-interrupt-handler/4667/4 "2014-07-15T14:41:23Z")

</div>

**[davedoors](https://sourceforge.net/u/davedoors/)** wrote on [Tuesday, July 15, 2014](https://sourceforge.net/p/freertos/discussion/382005/thread/cc3a289f/#7d23):

Each chip/compiler port necessarily has a different way of doing it because of the constraints of the architecture and the compiler syntax.
