# Error on C18 port?

**URL:** <https://forums.freertos.org/t/error-on-c18-port/2722>\
**Category:** Kernel\
**Created:** [October 19, 2008, 10:49pm UTC](https://forums.freertos.org/t/error-on-c18-port/2722 "2008-10-19T22:49:47Z")\
**Posts on this page:** 3\
**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:** [October 19, 2008, 10:49pm UTC](https://forums.freertos.org/t/error-on-c18-port/2722/1 "2008-10-19T22:49:47Z")

</div>

**[darukur](https://sourceforge.net/u/darukur/)** wrote on [Sunday, October 19, 2008](https://sourceforge.net/p/freertos/discussion/382005/thread/78407751/#e6db):

Hello all,

I´ve been dealing some time with different errors in FreeRTOS with C18 port.

Looking in the port i´ve found this:

#pragma code high\_vector=0x08  
static void prvLowInterrupt( void )  
{  
&nbsp;&nbsp;&nbsp; /\* Was the interrupt the tick? \*/  
&nbsp;&nbsp;&nbsp; if( PIR1bits.CCP1IF )  
&nbsp;&nbsp;&nbsp; {&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \_asm  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; goto prvTickISR  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \_endasm  
&nbsp;&nbsp;&nbsp; }

&nbsp;&nbsp;&nbsp; /\* Was the interrupt a byte being received? \*/  
&nbsp;&nbsp;&nbsp; if( PIR1bits.RCIF )  
&nbsp;&nbsp;&nbsp; {  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \_asm  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; goto vSerialRxISR  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \_endasm  
&nbsp;&nbsp;&nbsp; }

&nbsp;&nbsp;&nbsp; /\* Was the interrupt the Tx register becoming empty? \*/  
&nbsp;&nbsp;&nbsp; if( PIR1bits.TXIF )  
&nbsp;&nbsp;&nbsp; {  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if( PIE1bits.TXIE )  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \_asm  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; goto vSerialTxISR  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \_endasm  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }  
&nbsp;&nbsp;&nbsp; }  
}  
#pragma code

In accordance with C18 manual the pragma code place obviously code in the specified direction, but in the case of the interrupt it´s mean to be used just for a computed goto to the isr routine because the next positions (0x18) are mean for the low interrupt service.  
I think the previous code is writing beyond his range, also if you want to use priority level it definitely wont fit.

Here I post a modified example:

#pragma code high\_vector=0x08  
static void highIsr( void )  
{  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \_asm  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; goto prvHighInterrupt  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \_endasm  
}  
#pragma code

#pragma code low\_vector=0x18  
static void lowIsr( void )  
{  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \_asm  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; goto prvLowInterrupt  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \_endasm  
}  
#pragma code

#pragma interrupt prvHighInterrupt //save=PRODH, PRODL, TABLAT, section(".tmpdata")  
static void prvHighInterrupt( void )  
{  
&nbsp;&nbsp;&nbsp; /\*Timer Related Interrupt\*/  
&nbsp;&nbsp;&nbsp; if( PIR1bits.CCP1IF )  
&nbsp;&nbsp;&nbsp; {&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \_asm  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; goto prvTickISR  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \_endasm  
&nbsp;&nbsp;&nbsp; }  
}

#pragma interruptlow prvLowInterrupt //save=PRODH, PRODL, TABLAT, section(".tmpdata")  
static void prvLowInterrupt( void )  
{  
&nbsp;&nbsp;&nbsp; /\* Was the interrupt a byte being received? \*/  
&nbsp;&nbsp;&nbsp; if( PIR1bits.RCIF )  
&nbsp;&nbsp;&nbsp; {  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \_asm  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; goto vSerialRxISR  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \_endasm  
&nbsp;&nbsp;&nbsp; }

&nbsp;&nbsp;&nbsp; /\* Was the interrupt the Tx register becoming empty? \*/  
&nbsp;&nbsp;&nbsp; if( PIR1bits.TXIF )  
&nbsp;&nbsp;&nbsp; {  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if( PIE1bits.TXIE )  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \_asm  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; goto vSerialTxISR  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \_endasm  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }  
&nbsp;&nbsp;&nbsp; }  
}

Two more method def are required prvHighInterrupt and prvLowInterrupt.

Regards

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [October 20, 2008, 9:06am UTC](https://forums.freertos.org/t/error-on-c18-port/2722/2 "2008-10-20T09:06:44Z")

</div>

**[davedoors](https://sourceforge.net/u/davedoors/)** wrote on [Monday, October 20, 2008](https://sourceforge.net/p/freertos/discussion/382005/thread/78407751/#e6db/193f):

PIC18? - eek.

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [October 20, 2008, 1:46pm UTC](https://forums.freertos.org/t/error-on-c18-port/2722/3 "2008-10-20T13:46:50Z")

</div>

**[darukur](https://sourceforge.net/u/darukur/)** wrote on [Monday, October 20, 2008](https://sourceforge.net/p/freertos/discussion/382005/thread/78407751/#e6db/d536):

Yeap, PIC18 with MCC18.  
Does anyone have a newer working example for this micro?  
I mean MCC18 3.2 FreeRTOS 5.0.4 and a new micro (like PIC18F2620).  
I can not manage to get it working properly with this micro and compiler.  
In some point I always get a stack under-over flow reset or a read over a wrong code place.
