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 support@ccsinfo.com

interrupt_enabled()?

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



Joined: 10 Feb 2011
Posts: 241
Location: Vancouver, BC

View user's profile Send private message

interrupt_enabled()?
PostPosted: Tue Mar 15, 2011 10:17 am     Reply with quote

Hi,

Is there any way to check if a certain interrupt is enabled? interrupt_active() isn't what I want, I just would like to check if a certain interrupt is enabled and act upon that. Is there a generic way or should I just set my own global flag?
Thank you!
bkamen



Joined: 07 Jan 2004
Posts: 1611
Location: Central Illinois, USA

View user's profile Send private message

PostPosted: Tue Mar 15, 2011 11:21 am     Reply with quote

You can check the enable bit for the corresponding interrupt.

You can also set your own global bit if you want.

Either way will work.

-Ben
_________________
Dazed and confused? I don't think so. Just "plain lost" will do. :D
cerr



Joined: 10 Feb 2011
Posts: 241
Location: Vancouver, BC

View user's profile Send private message

PostPosted: Tue Mar 15, 2011 11:27 am     Reply with quote

Yes, I found this thread: http://www.ccsinfo.com/forum/viewtopic.php?t=16290&view=previous that explains somewhat how to check the interrupt flag but i've looked at the datasheet (18f87k22) and i don't see a specific enable bit for INT_RDA, but only the PEIE/GIEL: Peripheral Interrupt Enable bit thus I went ahead and implemented my own flag, it however would be nice to go "the generic way" if somehow possible, any clues?
bkamen



Joined: 07 Jan 2004
Posts: 1611
Location: Central Illinois, USA

View user's profile Send private message

PostPosted: Tue Mar 15, 2011 11:34 am     Reply with quote

You need to search for

RC2IE and TX2IE in the 18f87k22 datasheet.

I just looked and it took longer to download the datasheet than to thumb through the section on interrupts manually.

-Ben

EDIT: Sorry - Typo TX1IE & RC1IE
_________________
Dazed and confused? I don't think so. Just "plain lost" will do. :D


Last edited by bkamen on Tue Mar 15, 2011 11:44 am; edited 1 time in total
cerr



Joined: 10 Feb 2011
Posts: 241
Location: Vancouver, BC

View user's profile Send private message

PostPosted: Tue Mar 15, 2011 11:38 am     Reply with quote

But look what it says in the note to the PIR registers:

Note 1: Interrupt flag bits are set when an interrupt
condition occurs regardless of the state of
its corresponding enable bit or the Global
Interrupt Enable bit, GIE (INTCON<7>)

This is not what I want to know, I would like to know if it has been enabled and not if it's condition has occured...and the GIE only has the global peripherial bit.... weird...
bkamen



Joined: 07 Jan 2004
Posts: 1611
Location: Central Illinois, USA

View user's profile Send private message

PostPosted: Tue Mar 15, 2011 11:45 am     Reply with quote

cerr wrote:
But look what it says in the note to the PIR registers:

Note 1: Interrupt flag bits are set when an interrupt
condition occurs regardless of the state of
its corresponding enable bit or the Global
Interrupt Enable bit, GIE (INTCON<7>)

This is not what I want to know, I would like to know if it has been enabled and not if it's condition has occured...and the GIE only has the global peripherial bit.... weird...


Like I said, Look for TX1IE and RC1IE.

Those are the enable bits for UART1.

Your first post asks for checking on UART1... so I don't know why you're looking at GIE.

-Ben
_________________
Dazed and confused? I don't think so. Just "plain lost" will do. :D
cerr



Joined: 10 Feb 2011
Posts: 241
Location: Vancouver, BC

View user's profile Send private message

PostPosted: Tue Mar 15, 2011 11:53 am     Reply with quote

Okay, yes got it now... bit5 but how do I check for this? How do I tell the compiler to look at bit 5 in PIE1?
I see the #bit directive in the manual but am not quite sure how to use it - looked at examples but still... suggestions? Thanks
bkamen



Joined: 07 Jan 2004
Posts: 1611
Location: Central Illinois, USA

View user's profile Send private message

PostPosted: Tue Mar 15, 2011 11:59 am     Reply with quote

cerr wrote:
Okay, yes got it now... bit5 but how do I check for this? How do I tell the compiler to look at bit 5 in PIE1?
I see the #bit directive in the manual but am not quite sure how to use it - looked at examples but still... suggestions? Thanks


PCM just listed an example for someone else recently... it goes like this:



#byte PIR1 = getenv("sfr:PIR1")
#bit RC1IE = PIR1.5

or you can try

#bit RC1IE = getenv("bit:RC1IE")

I usually do the first one.

Now, in your code, you can say, if (RC1IE)


-Ben
_________________
Dazed and confused? I don't think so. Just "plain lost" will do. :D
SherpaDoug



Joined: 07 Sep 2003
Posts: 1640
Location: Cape Cod Mass USA

View user's profile Send private message

PostPosted: Tue Mar 15, 2011 12:01 pm     Reply with quote

How about the bit_test() function?
_________________
The search for better is endless. Instead simply find very good and get the job done.
cerr



Joined: 10 Feb 2011
Posts: 241
Location: Vancouver, BC

View user's profile Send private message

PostPosted: Tue Mar 15, 2011 12:28 pm     Reply with quote

bkamen wrote:

#byte PIR1 = getenv("sfr:PIR1")
#bit RC1IE = PIR1.5

or you can try

#bit RC1IE = getenv("bit:RC1IE")

I usually do the first one.

The first one actually doesn't work for me, I tried both and ended up sticking with the second one. Thanks Smile
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Mar 15, 2011 2:58 pm     Reply with quote

I posted a macro to do this in this thread:
http://www.ccsinfo.com/forum/viewtopic.php?t=42353

Here's a test program for it. These macros use the INT_xxx definitions
at the end of the PIC's .h file. So for the GLOBAL interrupt it actually
checks to see if both GIE and PEIE are set, because both those bits are
in the CCS definition.
Code:

#include <16F877.H>
#fuses XT, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)

#ifdef __PCM__
#define interrupt_enabled(x)  !!(*make8(x,1) & make8(x,0))
#endif
#ifdef __PCH__
#define interrupt_enabled(x)  !!(*(make8(x,1) | 0xF00) & make8(x,0))
#endif

//==========================================
void main()
{
int8 gie_flag;
int8 ext_flag;

if(interrupt_enabled(GLOBAL))
  {
   gie_flag = TRUE;
  }


if(interrupt_enabled(INT_EXT))
  {
   ext_flag = TRUE;
  }


while(1);
}


A few months ago I emailed CCS and proposed that they add this
feature to the compiler. But I guess they didn't like the idea.
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