# PIC24 interrupt

**URL:** <https://forums.freertos.org/t/pic24-interrupt/3054>\
**Category:** Kernel\
**Created:** [November 5, 2013, 7:37am UTC](https://forums.freertos.org/t/pic24-interrupt/3054 "2013-11-05T07:37:54Z")\
**Posts on this page:** 6\
**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:** [November 5, 2013, 7:37am UTC](https://forums.freertos.org/t/pic24-interrupt/3054/1 "2013-11-05T07:37:54Z")

</div>

**[amarjith](https://sourceforge.net/u/amarjith/)** wrote on [Tuesday, November 05, 2013](https://sourceforge.net/p/freertos/discussion/382005/thread/878e287e/#15b8):

On an interrupt routine I’ll have to use:

I’m using Binary Semaphores for interrupt synchronization.

as state on the FreeRTOS book:

The syntax of the interrupt service routine declaration and the macro called to force a context switch  
are both specific to the Open Watcom DOS port and will be different for other ports. Please refer to  
the examples that are included in the demo application for the port being used to find the actual syntax  
required.

static void \_\_interrupt \_\_far vExampleInterruptHandler( void )  
{  
static portBASE\_TYPE xHigherPriorityTaskWoken;  
xHigherPriorityTaskWoken = pdFALSE;  
/\* ‘Give’ the semaphore to unblock the task. _/  
xSemaphoreGiveFromISR( xBinarySemaphore, &xHigherPriorityTaskWoken );  
if( xHigherPriorityTaskWoken == pdTRUE )  
{  
/_ Giving the semaphore unblocked a task, and the priority of the  
unblocked task is higher than the currently running task - force  
a context switch to ensure that the interrupt returns directly to  
the unblocked (higher priority) task.  
NOTE: The actual macro to use to force  
ISR is dependent on the port. This is  
Open Watcom DOS port. Other ports may  
Refer to the examples provided for the  
the syntax required. \*/  
portSWITCH\_CONTEXT();  
a context switch from an  
the correct macro for the  
require different syntax.  
port being used to determine  
}  
}

As such portSWITCH\_CONTEXT is port dependent. I cannot find this function in the port of pic24F and interrupt handler function static void \_\_interrupt \_\_far vExampleInterruptHandler( void ),

\_\_asm{ int 0x82 } this line generates the interrupt.

/\* Install the interrupt handler. \*/  
\_dos\_setvect( 0x82, vExampleInterruptHandler );

Could you please explain this in detail to me.

---

<div class="post-metadata">

**Author:** ![rtel](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/rtel/32/31_2.png) [@rtel](https://forums.freertos.org/u/rtel)\
**Post date:** [November 5, 2013, 8:59am UTC](https://forums.freertos.org/t/pic24-interrupt/3054/2 "2013-11-05T08:59:58Z")

</div>

**[rtel](https://sourceforge.net/u/rtel/)** wrote on [Tuesday, November 05, 2013](https://sourceforge.net/p/freertos/discussion/382005/thread/878e287e/#b6eb):

> Please refer to the examples that are included in the demo application for  
> the port being used to find the actual syntax required.

This is the documentation page for the PIC24:

> **[FreeRTOS - PIC24 RTOS and dsPIC RTOS ports](https://www.freertos.org/portpic24_dspic.html)**
>
> FreeRTOS is a portable, open source, mini Real Time kernel. A free RTOS for small embedded systems

If you look at the “Interrupt Service Routines” section you will see it is actually much simpler on the PIC24. The demo in the FreeRTOS download (referenced from the same page) contains an example.

Regards.

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [November 5, 2013, 10:49am UTC](https://forums.freertos.org/t/pic24-interrupt/3054/3 "2013-11-05T10:49:38Z")

</div>

**[amarjith](https://sourceforge.net/u/amarjith/)** wrote on [Tuesday, November 05, 2013](https://sourceforge.net/p/freertos/discussion/382005/thread/878e287e/#bced):

Thank you so much sir. yes, i got it i have changed my code like this

void **attribute** (( **interrupt** , auto\_psv)) \_ExampleInterruptHandler( void )  
{  
static portBASE\_TYPE xHigherPriorityTaskWoken;  
xHigherPriorityTaskWoken = pdFALSE;  
/\* ‘Give’ the semaphore to unblock the task. _/  
xSemaphoreGiveFromISR( xBinarySemaphore, &xHigherPriorityTaskWoken );  
if( xHigherPriorityTaskWoken == pdTRUE )  
{  
/_ Giving the semaphore unblocked a task, and the priority of the  
unblocked task is higher than the currently running task - force  
a context switch to ensure that the interrupt returns directly to  
the unblocked (higher priority) task.  
NOTE: The actual macro to use to force  
ISR is dependent on the port. This is  
Open Watcom DOS port. Other ports may  
Refer to the examples provided for the  
the syntax required. \*/  
taskYIELD();

```
}

```

}

No errors now.

Could you clarify these lines too,

\_\_asm{ int 0x82 } this line generates the interrupt.

/ Install the interrupt handler. /  
\_dos\_setvect( 0x82, vExampleInterruptHandler );

i cannot find Install the interrupt handler.in demo.

---

<div class="post-metadata">

**Author:** ![rtel](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/rtel/32/31_2.png) [@rtel](https://forums.freertos.org/u/rtel)\
**Post date:** [November 5, 2013, 10:55am UTC](https://forums.freertos.org/t/pic24-interrupt/3054/4 "2013-11-05T10:55:16Z")

</div>

**[rtel](https://sourceforge.net/u/rtel/)** wrote on [Tuesday, November 05, 2013](https://sourceforge.net/p/freertos/discussion/382005/thread/878e287e/#5da9):

> Could you clarify these lines too,

They are only relevant to the x86 port, not the PIC24 port.

Regards.

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [November 5, 2013, 11:03am UTC](https://forums.freertos.org/t/pic24-interrupt/3054/5 "2013-11-05T11:03:23Z")

</div>

**[amarjith](https://sourceforge.net/u/amarjith/)** wrote on [Tuesday, November 05, 2013](https://sourceforge.net/p/freertos/discussion/382005/thread/878e287e/#93ad):

Ok. how i Install the interrupt handler in pic24. could you say the equivalent code in pic24?

---

<div class="post-metadata">

**Author:** ![rtel](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/rtel/32/31_2.png) [@rtel](https://forums.freertos.org/u/rtel)\
**Post date:** [November 5, 2013, 11:08am UTC](https://forums.freertos.org/t/pic24-interrupt/3054/6 "2013-11-05T11:08:52Z")

</div>

**[rtel](https://sourceforge.net/u/rtel/)** wrote on [Tuesday, November 05, 2013](https://sourceforge.net/p/freertos/discussion/382005/thread/878e287e/#6ebc):

As per the documentation page - interrupts are installed using the standard compiler syntax described in the compiler manual, and there is an example in \FreeRTOS\Demo\PIC24\_MPLAB\serial\serial.c.

Regards.
