CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Interrupt handler function.

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
jonfs2000



Joined: 19 Aug 2020
Posts: 4

View user's profile Send private message

Interrupt handler function.
PostPosted: Sat Aug 22, 2020 2:17 pm     Reply with quote

Hi,
I'm new to CCS pic compiler. I'm having difficulty getting the interrupt working. I want know the interrupt handling function.

I'm working on PIC18F67K22

The DATA SHEET says
The high-priority interrupt vector is at 0008h and the low-priority interrupt vector is at 0018h.

So when interrupt event happens, according to its priority, the control jumps to 0x0008 or 0x0018 to service the interrupt.

In the compiler I currently use, It has predefined function, and when interrupt occurs the program jump to either one of the Interrupt handler function (As per data sheet).

In side that I check for the source of interrupt (flag). The code looks similar as shown below.

Code:

void interrupt low_isr()      // 0x0018
{
   if(intcon3.INT1IF)
   {   // Handle external interrupt
      intcon3.INT1IF = 0;
   }

   //check for other low priority interrupt flag
}

void interrupt high_isr(void)      // 0x0008
{
   if (pir1.TMR2IF)
   {   // Handle timer overflow interrupt
      pir1.TMR2IF = 0;
   }
   
   //check for other high priority interrupt flag
}


How CCS works, I cannot find info on the header file for that PIC?

Many thanks
John
elcrcp



Joined: 11 Mar 2016
Posts: 62
Location: izmir / Turkey

View user's profile Send private message

PostPosted: Sat Aug 22, 2020 4:54 pm     Reply with quote

As you can see from the quote, there are 2 steps of interrupt handling in CCS, first is defining handler routine.
In this example an external interrupt source is defined by "#INT_EXT" line and below following function. There are different INT_XXX comands for different interrupt sources. Rule is you need to put the handler function just after INT_XXX command.
Second step is enabling interrupts, you can also do it by bit banging but there are predefined functions as you can see from the example.
Also you don't need to clear or check related interrupt flags since CCS does it for you automatically in handler.

PCM programmer wrote:
Your program is too complex. Look at this simple program first.
Every time an external interrupt on Pin B0 occurs, pin B1 will change
state. This program assumes that you have a clean input signal on
pin B0, and that the signal frequency is less than 10 KHz.
Code:

#include <16F887.h>
#fuses INTRC_IO,NOWDT,BROWNOUT,PUT,NOLVP
#use delay(clock = 4000000)

#INT_EXT
void ext_isr(void)
{
 output_toggle(PIN_B1);
}

//=======================
void main()
{
output_low(PIN_B1);  // Initially set Pin B1 low

ext_int_edge(L_TO_H);
clear_interrupt(INT_EXT);   
enable_interrupts(INT_EXT);
enable_interrupts(GLOBAL);

while(1);
}

_________________
There is nothing you can't do if you try
Ttelmah



Joined: 11 Mar 2010
Posts: 19506

View user's profile Send private message

PostPosted: Sun Aug 23, 2020 1:14 am     Reply with quote

and lots of other comments:
1) The CCS interrupt handler, automatically clears the interrupt flag
on the exit of the routine (unless you add the option 'NOCLEAR', which
then makes it your responsibility to clear the flag.
There is also an option 'CLEAR_FIRST', which will make the code clear the
interrupt at the start of the routine. Beware though quite a few interrupts
cannot be cleared until the hardware event has been cleared. So (for example),
INT_RB, cannot be clear until port B is read to clear the event. INT_RDAx
cannot be cleared until you read the serial character. So don't use
'CLEAR_FIRST' with any interrupt like this.
2) Your post implies you are using a PIC18 (since PIC16's generally don't
have high/low priority interrupts).
On the PIC18, adding the keyword 'HIGH' after the handler declaration, so:

#INT_EXT HIGH

Makes the compiler automatically set this interrupt to 'high' priority, and
put it's handler at 0x0008.
You need the #device declaration:
#device HIGH_INTS=TRUE before you can do this.
3) Then there are several other declaration keywords that affect how things
are handled:

#INT_xxx //default low priority handler with register saving
#INT_xxx FAST //High priority interrupt handler, no register saving
#INT_xxx HIGH //High priority handler with register saving

Look at the CCS example files. These show a lot of interrupt handling. Also
look at the code posted here, and in the code library.
temtronic



Joined: 01 Jul 2010
Posts: 9225
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sun Aug 23, 2020 7:22 am     Reply with quote

3.... Be sure to have an ISR for every interrupt you enable !!!
If not, sooner or later, an interrupt will trigger and PIC will either 'freeze' or do 'weird stuff'.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group