The PIC18F family I guess has high and low priority interrupt-service-routines, not just one ISR. My first time dealing with this and I can't seem to get the compiler (XC8) to recognize the two difference interrupts from some legacy code. Basically, I don't know where to look when hoping to figure out what to tell the compiler to mark these two functions as interrupts?
#include <xc8.h>
...
__interrupt(high_priority) void MyHighPriorityIsr(void)
{
// stuff
}
__interrupt(low_priority) void MyLowPriorityIsr(void)
{
// stuff
}
I'm getting:
error: (285) no identifier in declaration
error: (1275) only functions may be qualified "interrupt"
Page 34 of the compiler's user guide make it seem fine, but I'm getting errors and can't compile: http://ww1.microchip.com/downloads/en/DeviceDoc/MPLAB_XC8_C_Compiler_User_Guide.pdf
-
\$\begingroup\$ He said it's XC8! \$\endgroup\$Leon Heller– Leon Heller2014年04月03日 19:54:41 +00:00Commented Apr 3, 2014 at 19:54
-
1\$\begingroup\$ @LeonHeller After I asked him... \$\endgroup\$Matt Young– Matt Young2014年04月03日 19:56:29 +00:00Commented Apr 3, 2014 at 19:56
-
\$\begingroup\$ tarabyte, So are you satisfied with the answers or not. If not let me know exactly what processor are you using, so that I can check that my solution will work for you. I use PIC18F46K20 with LOW and HIGH priority interrupts, under XC8 compiler ver 1.30 and MPLAB 8.76 and all works fine, code compiles and actually does what it is supposed to do (ADC Ints, TMR0 and TMR1 Ints, Ints on pin change (IOCB)). But I must admit it took me hours to figure out which bits in which registers to set and which form of ISR def/decl to use. XC8 manual is too generic. They should have abandoned C18 legacy and n \$\endgroup\$derlo– derlo2014年05月12日 10:29:17 +00:00Commented May 12, 2014 at 10:29
2 Answers 2
void low_priority interrupt Low_Priority_Interrupt(void) {
if (TMR1IE && TMR1IF) {
TMR1H = 0xFE;//Pre load for 125 ms
Timer1_Isr();
TMR1IF = 0;
return;
}
}
void high_priority interrupt High_Priority_Interrupt(void) {
if (TX2IE && TX2IF) {
SerialTx_Isr();
TX2IF = 0;
return;
}
if (RC2IE && RC2IF) {
SerialRx_Isr();
RC2IF = 0;
return;
}
}
Is it possible that you aren't declaring your functions properly?
Higher in your code, you should have the declarations:
void __interrupt(high_priority) MyHighPriorityIsr(void);
void __interrupt(low_priority) MyLowPriorityIsr(void);
Then, later, your function definitions:
void __interrupt(high_priority) MyHighPriorityIsr(void)
{
// stuff
}
void __interrupt(low_priority) MyLowPriorityIsr(void)
{
// stuff
}
Also, notice that "void" comes before __interrupt()
Good luck!
-
\$\begingroup\$ all the permutations of where i place __interrupt seem to not allow me to compile :( \$\endgroup\$tarabyte– tarabyte2014年04月03日 20:17:23 +00:00Commented Apr 3, 2014 at 20:17
-
1\$\begingroup\$ That is not the XC8 way of writing ISRs. \$\endgroup\$Matt Young– Matt Young2014年04月03日 20:37:16 +00:00Commented Apr 3, 2014 at 20:37
-
\$\begingroup\$ @MattYoung I believe you, since it didn't work for terabyte. But, i took it directly from the the XC Users Guide (version D), section 2.5.10.3. For example, it says that for 8-bit compilers, to change
void interrupt myIsr(void)
tovoid __interrupt(high_priority) myIsr(void)
and to changevoid interrupt low_priority myLoIsr(void)
tovoid __interrupt(low_priority) myLoIsr(void)
. I copied and pasted... Could you let me know how it should be done? I haven't migrated from Microchip's C18 yet :) \$\endgroup\$bitsmack– bitsmack2014年04月03日 21:12:08 +00:00Commented Apr 3, 2014 at 21:12 -
\$\begingroup\$ What Eric Friesen said. The pertinent part of the XC8 manual is section 5.9. And stick with C18, XC8 is inferior. \$\endgroup\$Matt Young– Matt Young2014年04月03日 23:20:42 +00:00Commented Apr 3, 2014 at 23:20
-
\$\begingroup\$ I don't like either. They have oddities that are annoying after using c32. \$\endgroup\$Erik Friesen– Erik Friesen2014年04月04日 01:44:32 +00:00Commented Apr 4, 2014 at 1:44