• AVR Freaks

Helpful ReplyHot!Interrupt routine in XC8

Page: 12 > Showing page 1 of 2
Author
CitizenOfDreams
New Member
  • Total Posts : 9
  • Reward points : 0
  • Joined: 2010/11/03 11:59:12
  • Location: 0
  • Status: offline
2018/07/08 10:56:28 (permalink)
1 (1)

Interrupt routine in XC8

Never mind, found the answer.
 
post edited by CitizenOfDreams - 2018/07/08 11:01:29
#1
katela
Super Member
  • Total Posts : 1281
  • Reward points : 0
  • Joined: 2013/06/11 05:25:18
  • Location: South Africa
  • Status: offline
Re: Interrupt routine in XC8 2018/07/08 15:03:52 (permalink) ☄ Helpfulby JCLA 2018/10/17 13:49:43
+5 (7)
What if your answer could assist somebody else? That's the purpose of a forum!

Free online Microcontroller Tutorials and Projects for Hobbyists and students. From beginners to advanced. Website: www.studentcompanion.co.za
YouTube Tutorials: https://www.youtube.com/StudentCompanionSA
#2
CitizenOfDreams
New Member
  • Total Posts : 9
  • Reward points : 0
  • Joined: 2010/11/03 11:59:12
  • Location: 0
  • Status: offline
Re: Interrupt routine in XC8 2018/07/09 02:31:04 (permalink)
+6 (6)
It was just a simple case of RTFM.
I tried XC8 for the first time, so I wrote my interrupt routine the same way I used to do it in HiTech C:
void interrupt my_isr_routine (void) {
}

The compiler replied with an error: variable has incomplete type 'void'.
Then I read the XC8 manual and found the correct way:
void __interrupt () my_isr_routine (void) {
}

#3
qɥb
Monolothic Member
  • Total Posts : 3332
  • Reward points : 0
  • Joined: 2017/09/09 05:07:30
  • Location: Jupiter
  • Status: offline
Re: Interrupt routine in XC8 2018/07/09 02:35:40 (permalink)
+5 (5)
Which version of XC8?
All versions prior to the latest (v2.0) would be perfectly happy with the HiTech syntax.
They only require the __interrupt version when in the restrictive CCI mode.
 

This forum is mis-configured so it only works correctly if you access it via https protocol.
The Microchip website links to it using http protocol. Will they ever catch on?
PicForum "it just works"
#4
CitizenOfDreams
New Member
  • Total Posts : 9
  • Reward points : 0
  • Joined: 2010/11/03 11:59:12
  • Location: 0
  • Status: offline
Re: Interrupt routine in XC8 2018/07/09 03:31:11 (permalink)
0
Naturally, I downloaded the latest MPLAB X IDE (4.20) and the latest XC8 (2.00). I presume the CCI mode is enabled by default?
#5
qɥb
Monolothic Member
  • Total Posts : 3332
  • Reward points : 0
  • Joined: 2017/09/09 05:07:30
  • Location: Jupiter
  • Status: offline
Re: Interrupt routine in XC8 2018/07/09 03:36:46 (permalink)
+3 (3)
No, but that combination will enable C99 mode, which is new to XC8 v2, which also disallows the interrupt keyword.
V2 is "hot off the press", so if you ask any more questions in the near future, you should mention you are using v2.
 

This forum is mis-configured so it only works correctly if you access it via https protocol.
The Microchip website links to it using http protocol. Will they ever catch on?
PicForum "it just works"
#6
PICcie
New Member
  • Total Posts : 14
  • Reward points : 0
  • Joined: 2018/03/02 12:15:35
  • Location: 0
  • Status: offline
Re: Interrupt routine in XC8 2018/08/02 02:58:42 (permalink)
0
Hello,
 
Personnaly, I use this method. It's works fine also with MPLAB X v5.00 and XC8 v2.00
 
void interrupt my_isr(void)
{

}

 
Best regards,
#7
qɥb
Monolothic Member
  • Total Posts : 3332
  • Reward points : 0
  • Joined: 2017/09/09 05:07:30
  • Location: Jupiter
  • Status: offline
Re: Interrupt routine in XC8 2018/08/02 03:14:40 (permalink)
+4 (4)
PICcie
...It's works fine also with MPLAB X v5.00 and XC8 v2.00

According to the manual, it will only work in C90 mode in v2.0

This forum is mis-configured so it only works correctly if you access it via https protocol.
The Microchip website links to it using http protocol. Will they ever catch on?
PicForum "it just works"
#8
pridy
New Member
  • Total Posts : 3
  • Reward points : 0
  • Joined: 2017/02/19 04:42:01
  • Location: 0
  • Status: offline
Re: Interrupt routine in XC8 2018/09/16 13:38:18 (permalink)
0
PICcie
Hello,
 
Personnaly, I use this method. It's works fine also with MPLAB X v5.00 and XC8 v2.00
 
void interrupt my_isr(void)
{

}

 
Best regards,




Hello,
that's exactly the way I learned it and always used it.
 
But now with MPLAB 5 and CX8 v2.00 compilter, it complaints as mentioned above
 
CompilerOutputerror: variable has incomplete type 'void'

 
 
As already mentioned from people in the discussion, I will check the mode the xc8 is running in (C99 mode? CCI mode?)
I did not configure anything to go into a certain mode; Everything should be default, since I just started MPLAB, created a new project and selected the XC8 compiler (without setting or unsetting any options) and the debug tool (PicKit3).
 
Update: I checked the settings and the compiler and linker is set to C99 mode.
In the discussion is mentioned for C99 the usage of "__interrupt" shall be used. But also this throws the same error.
Any suggestions?
 
Someone also has this behaviour? Any hints?
 
Thanks and best regards,
-p
post edited by pridy - 2018/09/16 13:44:38
#9
mad_c
Super Member
  • Total Posts : 1188
  • Reward points : 0
  • Joined: 2010/12/12 17:48:27
  • Location: Brisbane, Australia
  • Status: offline
Re: Interrupt routine in XC8 2018/09/16 13:53:45 (permalink)
+1 (1)
pridy
In the discussion is mentioned for C99 the usage of "__interrupt" shall be used. But also this throws the same error.
Any suggestions?
 

Note that __interrupt() has to have the brackets, even if they are empty.
 
Jeff.
 
#10
pridy
New Member
  • Total Posts : 3
  • Reward points : 0
  • Joined: 2017/02/19 04:42:01
  • Location: 0
  • Status: offline
Re: Interrupt routine in XC8 2018/09/16 14:06:30 (permalink)
0
mad_c
pridy
In the discussion is mentioned for C99 the usage of "__interrupt" shall be used. But also this throws the same error.
Any suggestions?
 

Note that __interrupt() has to have the brackets, even if they are empty.
 
Jeff.

Does that mean the declaration of an interrupt service routine should like this?

void interrupt() my_isr(void)
{
        //do somehting
}

 
 
Update:
While playing around and trying to get compilable, I found out (xc8 v2.00 in C99 mode) that the following is compilable:
 
Prototype in header file (Is it even needed??)

void interrupt(void);

 
Function implementation in c file

void interrupt(void){
        //some code
}

 
But I did not test if it works on the target. Only compilable.
Also I get the warning thrown:
CompilerOutput
my_lib/my_interrupt.c:35:: warning: (520) function "_interrupt" is never called

This is quite unusual, because an interrupt is "called" by hardware. So the compiler should know that this function is called under certain circumstances which are not visible from the code.
Or do I miss something here?
post edited by pridy - 2018/09/16 14:17:54
#11
qhb
Superb Member
  • Total Posts : 9998
  • Reward points : 0
  • Joined: 2016/06/05 14:55:32
  • Location: One step ahead...
  • Status: offline
Re: Interrupt routine in XC8 2018/09/16 15:28:00 (permalink) ☄ Helpfulby pridy 2018/09/18 12:13:03
+4 (4)
Those declarations are pointless. They are NOT declaring an interrupt function, just a normal function named "interrupt", which is NOT the same thing.
 
 

Nearly there...
#12
qhb
Superb Member
  • Total Posts : 9998
  • Reward points : 0
  • Joined: 2016/06/05 14:55:32
  • Location: One step ahead...
  • Status: offline
Re: Interrupt routine in XC8 2018/09/16 15:59:20 (permalink) ☄ Helpfulby pridy 2018/09/18 12:12:33
+4 (4)
pridy
...
Does that mean the declaration of an interrupt service routine should like this?
void interrupt() my_isr(void)
{
        //do somehting
}

That IS how you should do it.
Your later attempt was just a red herring that did not define an interrupt service at all.
 
 

Nearly there...
#13
pridy
New Member
  • Total Posts : 3
  • Reward points : 0
  • Joined: 2017/02/19 04:42:01
  • Location: 0
  • Status: offline
Re: Interrupt routine in XC8 2018/09/18 12:19:42 (permalink)
+1 (1)
I would like to clarify the double underscore.
This is the correct C99 syntax

void __interrupt() my_isr(void)

(Of course the project settings have to set XC8 v2.00 in C99 mode.)
 
And here is the full detailed explanation in the forum: https://www.microchip.com/forums/FindPost/1067160
Sorry, I didnt find this before the posts.
 
Thanks for your quick replies and hints.
Best regards,
-p
#14
seyyah
Super Member
  • Total Posts : 609
  • Reward points : 0
  • Joined: 2004/05/14 12:49:28
  • Status: offline
Re: Interrupt routine in XC8 2018/10/05 00:37:23 (permalink) ☄ Helpfulby pridy 2019/01/05 15:55:38
+1 (1)
In addition; low and high priority keywords are also changed like this:
 
void  __interrupt(low_priority) myLowIsr(void)
void  __interrupt(high_priority) myHighIsr(void)
#15
cobusve
Super Member
  • Total Posts : 492
  • Reward points : 0
  • Joined: 2012/04/02 16:15:40
  • Location: Chandler
  • Status: offline
Re: Interrupt routine in XC8 2019/01/30 13:53:40 (permalink)
+1 (1)
And note that it is not just interrupts syntax which has been changed. Please read the release notes and the compiler users guide, a lot of old code is hanging around all over the world and giving people headaches because they were using the non-standard syntax like interrupt, @0x200 for locating variables, bit types, etc.
 
There is some more info and links to the documents here : https://www.microforum.cc/topic/38-help-with-this-error-error-variable-has-incomplete-type-void/
 

Also take a look at https://www.microforum.cc/ - a great resource for information on PIC and AVR microcontrollers and embedded programming in general. You can also post questions to the experts there.
#16
DungeonLords
New Member
  • Total Posts : 2
  • Reward points : 0
  • Joined: 2019/05/05 08:41:21
  • Location: 0
  • Status: offline
Re: Interrupt routine in XC8 2019/05/07 14:24:36 (permalink)
0
 
How to set interrupt via XC8 for Atmega? I read MPLAB_XC8_C_Compiler_User_Guide_for_AVR.
An example of an interrupt function is shown below.
void __interrupt(SPI_STC_vect_num) spi_Isr(void) {    
//I coment this: process(SPI_SlaveReceive());
return;
}
Error
../main.c:10:18: error: expected declaration specifiers or '...' before numeric constant
from ../main.h:3,
void __interrupt(SPI_STC_vect_num) spi_Isr(void) {
#17
qhb
Superb Member
  • Total Posts : 9998
  • Reward points : 0
  • Joined: 2016/06/05 14:55:32
  • Location: One step ahead...
  • Status: offline
Re: Interrupt routine in XC8 2019/05/07 15:36:19 (permalink)
+2 (2)
Which AVR part have you selected in the project properties?
 Did you #include <xc.h> ?
 
post edited by qhb - 2019/05/07 15:39:09

Nearly there...
#18
DungeonLords
New Member
  • Total Posts : 2
  • Reward points : 0
  • Joined: 2019/05/05 08:41:21
  • Location: 0
  • Status: offline
Re: Interrupt routine in XC8 2019/05/07 15:45:18 (permalink)
0
atmega88p and yes #include <xc.h>, look
post edited by DungeonLords - 2019/05/07 15:48:46

Attached Image(s)

#19
qhb
Superb Member
  • Total Posts : 9998
  • Reward points : 0
  • Joined: 2016/06/05 14:55:32
  • Location: One step ahead...
  • Status: offline
Re: Interrupt routine in XC8 2019/05/07 15:52:03 (permalink)
0 (2)
What is in main.h ?
You should put your own header files AFTER the system ones.
 

Nearly there...
#20
Page: 12 > Showing page 1 of 2
Jump to:
© 2019 APG vNext Commercial Version 4.5