  | 
	  | 
		 
	 
	
		| View previous topic :: View next topic   | 
	 
	
	
		| Author | 
		Message | 
	 
	
		
			lindsay.wilson.88
 
 
  Joined: 11 Sep 2024 Posts: 40
  
			
			 
			 
			
			
			
			
			
			
			
  
		  | 
		
			
				| Using OR in the argument for enable_interrupts()? | 
			 
			
				 Posted: Tue Sep 24, 2024 10:16 am     | 
				     | 
			 
			
				
  | 
			 
			
				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: 19967
  
			
			 
			 
			
			
			
			
			
			
			
  
		  | 
		
			
				 | 
			 
			
				 Posted: Tue Sep 24, 2024 12:24 pm     | 
				     | 
			 
			
				
  | 
			 
			
				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
  
			
			 
			 
			
			
			
			
			
			
			
  
		  | 
		
			
				 | 
			 
			
				 Posted: Tue Sep 24, 2024 7:10 pm     | 
				     | 
			 
			
				
  | 
			 
			
				| Ahhh, that makes sense now, thanks! | 
			 
		  | 
	 
	
		  | 
	 
	
		 | 
	 
 
  
	 
	    
	   | 
	
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
  
		 |