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

Interrupt on change RB0-RB3

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



Joined: 09 Jun 2004
Posts: 52

View user's profile Send private message

Interrupt on change RB0-RB3
PostPosted: Fri Sep 25, 2015 7:39 am     Reply with quote

I'm using a PIC 16F887, compiler v4.069

The 'F887 datasheet shows interrupt on change for all bits in Port B, but it looks like the CCS Compiler #int_RB only looks for changes on RB4-RB7.

I would like to interrupt on any RB pin changing. What do I need to do?

Cheers,
Steve
Ttelmah



Joined: 11 Mar 2010
Posts: 19447

View user's profile Send private message

PostPosted: Fri Sep 25, 2015 8:42 am     Reply with quote

Just set the required bit in the IOCB register.

The interrupt responds to all pins with bits set in this register.
Code:

#define IOCB=getenv("SFR:IOCB")

//then to enable RB3 (say)
   bit_set(IOCB,3);

//to enable all
   IOCB=0xFF;

//to disable all
   IOCB=0;
eyewonder300



Joined: 09 Jun 2004
Posts: 52

View user's profile Send private message

PostPosted: Fri Sep 25, 2015 9:35 am     Reply with quote

Thanks, I'll try this later today.

Cheers,
Steve
eyewonder300



Joined: 09 Jun 2004
Posts: 52

View user's profile Send private message

Success
PostPosted: Mon Oct 05, 2015 1:22 pm     Reply with quote

Thanks to all, I have my prog working as needed. Some of the problems were from my fuse selections (or lack thereof), and not understanding the interrupt enabling, & testing.

My hardware is a quadrature encoder chip, and it outputs a low going pulse on one pin for count up, and a low going pulse on another pin for count down. The chip prohibits both from being low at the same time, so whichever (port RB4 or RB5) is low is my count direction. If both are hi, then some other interrupt on the port was active.

Here is the code that worked for me:

Code:
// This function reads Port B without changing the TRIS.
//int8 input_state_b(void)
//   {
//   #byte PortB = getenv("SFR:PORTB") 
//   return(PortB);
//   }


#int_RB
void  RB_isr(void)
   {
   current = input_b();
   disable_interrupts(global);
   if ((!bit_test(current,5)))    //LOW signal is COUNT UP pulse from encoder
      {
      counter_val = counter_val + 1;
      printf(vfd_putc,"\fCounter: %3u",counter_val);
      }
   if ((!bit_test(current,4)))    //LOW signal is COUNT DOWN pulse from encoder
      {
      counter_val = counter_val - 1;
      printf(vfd_putc,"\fCounter: %3u",counter_val);
      }
   }

void main()
   {
   counter_val = 0;
   vfd_init();
   vfd_putc("Hello, Steve");
   delay_ms(1000);
   vfd_putc("\fWaiting for ISR");
   delay_ms(1000);
   set_tris_b(0x3F);
   port_b_pullups(0b00111111);
   setup_adc_ports(NO_ANALOGS|VSS_VDD);
   setup_adc(ADC_OFF);
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DISABLED,0,1);
   setup_comparator(NC_NC_NC_NC);// This device COMP currently not supported by the PICWizard
//   enable_interrupts(INT_RB);
   enable_interrupts(INT_RB4);
   enable_interrupts(INT_RB5);
   clear_interrupt(int_rb);
   enable_interrupts(GLOBAL);
//Setup_Oscillator parameter not selected from Intr Oscillator Config tab

   // TODO: USER CODE!!
   while(true){};
   }

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