| View previous topic :: View next topic | 
	
	
		| Author | Message | 
	
		| Will Guest
 
 
 
 
 
 
 
			
			
			
			
			
			
			
			
			
 
 | 
			
				| Simple External Interrupt Handler |  
				|  Posted: Sat Oct 13, 2007 3:28 pm |   |  
				| 
 |  
				| I need to be able to run an ISR each time a line on a particular port changes.  Sounds simple enough but I keep getting preprocessor errors when using any other port but B. 
 What am I missing?  Below complies fine but doesn't seem to turn the
 
 --
 #include <16F877A.h>
 
 #FUSES NOWDT
 #FUSES HS
 #FUSES NOPUT
 #FUSES NOPROTECT
 
 #use delay(clock=20000000)
 
 #include <stdlib.h>
 
 
 #INT_RB
 void alarm_ISR(void)
 {
 int8 tpb;
 
 tpb = input_b();
 
 if (tpb & 0x01)
 {
 output_high(PIN_A5);
 }
 else output_low(PIN_A5);
 }
 
 void main(void)
 {
 set_tris_b(0b00000111);
 
 enable_interrupts(INT_RB);
 enable_interrupts(GLOBAL);
 }
 |  | 
	
		|  | 
	
		| PCM programmer 
 
 
 Joined: 06 Sep 2003
 Posts: 21708
 
 
 
			    
 
 | 
			
				|  |  
				|  Posted: Sat Oct 13, 2007 3:45 pm |   |  
				| 
 |  
				| Before you do anything else, add the NOLVP fuse.   Without that fuse, the PIC will lock-up if pin RB3 goes high.
 
 Also, when you post code, enable the tickbox below the posting window
 to disable HTML.    Then you won't get lines like this:
 
 |  | 
	
		|  | 
	
		| Ttelmah Guest
 
 
 
 
 
 
 
			
			
			
			
			
			
			
			
			
 
 | 
			
				|  |  
				|  Posted: Sat Oct 13, 2007 4:21 pm |   |  
				| 
 |  
				| Read the data sheet. What pins does the RB interrupt respond to?.
 Does this include bit 0 of the port, which you are testing?.....
 Also, remember the need to have something to stop the main running off the end, and sending the processor to sleep.
 
 Best Wishes
 |  | 
	
		|  | 
	
		| Will Guest
 
 
 
 
 
 
 
			
			
			
			
			
			
			
			
			
 
 | 
			
				|  |  
				|  Posted: Sat Oct 13, 2007 4:52 pm |   |  
				| 
 |  
				| I'll check again, but I was sure it responded to A5-A7 on port A, all of B. 
 The code above doesn't seem to respond either and I forgot my serial cable back on campus...
 |  | 
	
		|  | 
	
		| Ttelmah Guest
 
 
 
 
 
 
 
			
			
			
			
			
			
			
			
			
 
 | 
			
				|  |  
				|  Posted: Sun Oct 14, 2007 2:22 am |   |  
				| 
 |  
				| No, it responds to B4 to B7 _only_, you are testing B0.... Sction 12.10.3 in the data sheet.
 On some chips, it responds to other bits, but not on the 877
 
 Best Wishes
 |  | 
	
		|  | 
	
		|  |