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

Using OR in the argument for enable_interrupts()?

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
lindsay.wilson.88



Joined: 11 Sep 2024
Posts: 40

View user's profile Send private message

Using OR in the argument for enable_interrupts()?
PostPosted: Tue Sep 24, 2024 10:16 am     Reply with quote

Hi,

I'm probably being thick, but this caused me to tear my hair out for a good while!

In some functions, it's possible to combine multiple arguments/values with the | (or) operator - for example:

Code:
setup_timer_0 (TO_INTERNAL|TO_DIV2);


I then was trying to use enable_interrupts() to enable both global and timer 2 interrupts, and assumed that it would be possible to combine the two "levels" with an or operator again, i.e. like:

Code:
enable_interrupts(GLOBAL|INT_TIMER2);


However, this doesn't work. Looking at the listing, it writes to the TOSU register (something about the stack, I'm not sure). Whereas, if I do separate:

Code:
enable_interrupts(INT_TIMER2);
enable_interrupts(GLOBAL);


these write to PIE1 and INTCON, as I'd expect. And, the interrupts then work.

Could someone please clarify all this? Am I mistaken about combining arguments in this way?

Thanks,

Lindsay
Ttelmah



Joined: 11 Mar 2010
Posts: 19495

View user's profile Send private message

PostPosted: Tue Sep 24, 2024 12:24 pm     Reply with quote

It's down to the nature of the settings. The former is a value that sets
bits in one or more registers. These can be or'ed (and if you look at
the remarks for these values, the .h file tells you this). Howeevr the
interrupt setting is a specific value with a specific meaning. Each interrupt
has a specific numeric code, and or'ing these will set somthing completely
different.
lindsay.wilson.88



Joined: 11 Sep 2024
Posts: 40

View user's profile Send private message

PostPosted: Tue Sep 24, 2024 7:10 pm     Reply with quote

Ahhh, that makes sense now, thanks!
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