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

having trouble with interrupt change on B

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



Joined: 20 Apr 2007
Posts: 2

View user's profile Send private message

having trouble with interrupt change on B
PostPosted: Tue Apr 24, 2007 9:14 am     Reply with quote

Hi,

I'm having trouble getting the #int_RB working right

what i'm trying to do is use the pull internal pull ups to keep the pins high, and drive one pin low when i need to with a switch.
here is most of the code
what am i doing wrong

Code:


#define Latch PIN_A0
#define Buzz PIN_A1
#define tach  PIN_B5

#int_rb
void  changeonb_isr()
  {
   output_low(Buzz);
   delay_ms(1000);
  }

void main()
{

   setup_adc_ports(NO_ANALOGS|VSS_VDD);
   setup_adc(ADC_OFF|ADC_TAD_MUL_0);
   setup_psp(PSP_DISABLED);
   setup_spi(SPI_MASTER|SPI_L_TO_H|SPI_CLK_DIV_4);
   setup_wdt(WDT_OFF);
   setup_timer_0(RTCC_INTERNAL);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DISABLED,0,1);
   setup_comparator(NC_NC_NC_NC);
   setup_vref(FALSE);
   setup_oscillator(OSC_32MHZ);
  // setup_oscillator(False);
   port_b_pullups(TRUE);
   set_tris_e(!000);
   set_tris_b(0xFF);
   disable_interrupts(INT_RB);
   disable_interrupts(GLOBAL);
   

   output_low(Buzz);
   delay_ms(3000);
   output_high(Buzz);
   delay_ms(2000);
   output_low(Buzz);
   delay_ms(3000);
   output_high(Buzz);

   enable_interrupts(INT_RB);
   enable_interrupts(GLOBAL);
   
   
While(true)
   {
      delay_cycles(5);
      output_high(Buzz);
   }
}




Buzz=PIN_A1 is connected to an led. when the pic first starts it will flash the led, but once interrupts are turned on, the led stays on permenantly, even though there is no change on any pin, and they are held up with internal resistors.

Any suggestions. Thanks a lot.

Edit: I guess I should have mentioned that this is for a PIC18F4520 and that im using compiler version 4.024 Thanks
Ttelmah
Guest







PostPosted: Tue Apr 24, 2007 10:24 am     Reply with quote

The PortB 'change' interrupt, happens,whenever the state of PortB doesn't match the value stored in an internal latch.
Three things therefore need to be done:
1) You _must_ read PortB in the interrupt handler. Otherwise the latch will not be reset, and the interrupt will occur permanently.
2) Once any configuration is done to the pins (even something like turning on the pull-ups), you again _must_ read the port to reset the latch.
3) Before enabling the interrupt, and after reading the port, you should clear the interrupt flag, otherwise if the flag has been set, and interrupt will immediately occur.

Best Wishes
rnielsen



Joined: 23 Sep 2003
Posts: 852
Location: Utah

View user's profile Send private message

PostPosted: Tue Apr 24, 2007 10:49 am     Reply with quote

Remember, this in an interrupt on _change_. This means that you will get an interrupt when a pin goes to a Low state. You will, also, get an interrupt when it returns to a High state. You'll get an interrupt every time it changes state so you'll need to be able to handle the return-to-normal state in the ISR.

Ronald
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