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

Interrupt on port b not working

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



Joined: 18 Jun 2012
Posts: 19

View user's profile Send private message

Interrupt on port b not working
PostPosted: Tue Jul 17, 2012 2:37 am     Reply with quote

Hi,
I was testing port b interrupt.
Am using.
PIC16F886 @4MHz Internal Osc.
CCS C Version 4.105

I have connected LED on A0 and giving low signal on RB7-RB4 but no LED glow.
The pins RB7-RB4 is high, checked by logic probe.
Please where I did mistake.
Whenever I give logic zero to any of pin RB7-RB4 the LED should glow.


Code:


#include "KBD_WakeUp.h"


#use delay(4000000)
#int_RB

#define LED PIN_A0



void  RB_isr(void)
{
clear_interrupt(INT_RB);
output_bit(LED, 1);
delay_ms(500);
}




void main()
{

   setup_adc_ports(NO_ANALOGS|VSS_VDD);
   setup_adc(ADC_CLOCK_DIV_2);
   setup_spi(SPI_SS_DISABLED);
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DISABLED,0,1);
   setup_ccp1(CCP_OFF);
   setup_comparator(NC_NC_NC_NC);// This device COMP currently not supported by the PICWizard
   enable_interrupts(INT_RB);
   enable_interrupts(GLOBAL);
   setup_oscillator(OSC_4MHZ);

   // TODO: USER CODE!!
   
 
   
   
   
   set_tris_b(0x0F);
   ext_int_edge(H_TO_L);
   output_bit(LED,0);
   
   while(1)
   {
   }

}

FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Tue Jul 17, 2012 3:25 am     Reply with quote

Two suggestions:
- Review the PIC16F886 datasheet for the actual pin change interrupt features that are not verbosely explained in the CCS C help or manual.
- Check the INT_RBx constants in 16F886.h to be used with enable/disable_interrupts().
sseidman



Joined: 14 Mar 2005
Posts: 159

View user's profile Send private message

PostPosted: Tue Jul 17, 2012 7:08 am     Reply with quote

Try putting the #int_RB line right before the function def, without the #define in the middle. Don't know if this is the answer, but it couldn't hurt.
Ttelmah



Joined: 11 Mar 2010
Posts: 19484

View user's profile Send private message

PostPosted: Tue Jul 17, 2012 12:19 pm     Reply with quote

Sequence of things wrong:

setup_spi(SPI_SS_DISABLED);

Correct syntax is:

setup_spi(FALSE);

The earlier line _enables_ the SPI, but with slave select turned off.
This is an error in the wizard.

Code:

void  RB_isr(void)
{
clear_interrupt(INT_RB);
output_bit(LED, 1);
delay_ms(500);
}


This does _not_ define an ISR handler. and wouldn't work if it did.

You need:
Code:

#INT_RB
void  RB_isr(void) {
   int dummy;
   dummy=input_b();
   output_bit(LED, 1);
}


Note the #INT stuff immediately in front of the routine. This is _required_. Then, you can't clear the interrupt, and this is not required. The _compiler_ will automatically clear the interrupt when the routine exits, but neither you or the compiler can clear this interrupt, _until_ you read the port. It'll set again immediately....

Then:
ext_int_edge(H_TO_L);

does nothing. This is for the INT_EXT, _not_ the interrupt on change feature.

Next, _never_ delay in an interrupt handler. Repeat the mantra a hundred times:

Interrupt handlers should do what they have to do, and exit as quickly as possible. Delays in interrupt handlers should be avoided at all costs.

Finally, check what pins INT_RB works on. You are setting the pins that this uses as outputs. Not goingto get much detection on these pins....

I think you are possibly confusing INT_RB, with INT_EXT, which is on RB0, and is affected by ext_int_edge(H_TO_L). If so, you are enabling the wrong interrupt.....

Best Wishes
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