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

Ext Interrupt only triggered on port B pin 0

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



Joined: 08 Sep 2008
Posts: 38

View user's profile Send private message

Ext Interrupt only triggered on port B pin 0
PostPosted: Mon Sep 08, 2008 11:50 am     Reply with quote

I need an external interrupt that is triggered by a change on ANY pins of port b. Here is the code that works with pin 0 and no others. I have tried everything I can think of. Am I missing something simple?

Code:

#include <16F887.h>   // PIC Device Header
#device ADC=8 PASS_STRINGS=IN_RAM // HIGH_INTS=TRUE
#include <stdlib.h>

// --- FUSES ------------------------------------------------
#FUSES LP         // Use low power osc
#FUSES INTRC_IO   // Internal RC Osc
#FUSES NOWDT      // No Watch Dog Timer
#fuses NODEBUG    // No Debug mode for ICD
#fuses PROTECT    // Code protected from reading
#fuses NOWRT      // Program memory not write protected
#fuses NOLVP      // No low voltage prgming
#fuses NOCPD      // No EE protection
#fuses NODEBUG    // No Debug mode for ICD
#fuses NOBROWNOUT // No brownout reset

#use delay( clock=31000 )

// === Global Variables ===
int8  gSleepcounter = 0;
int1  gIsSleeping = 0;


// === TIMER 2 ===================================
#INT_TIMER2  // Service Timer 2
void isr_timer2(void) {

   gSleepcounter++;
   if (gSleepcounter > 10) {
      gIsSleeping = 1;
   }
}

// === external interrupt  =============
#INT_EXT
void ext_isr() {
   gIsSleeping   = 0;
   gSleepcounter = 0;
}

// === Initialize =============================
void initialize() {
   setup_oscillator(OSC_31KHZ);

   setup_timer_2(T2_DIV_BY_16, 255, 1);     // Timer 2 (DIV_BY, Period, Post)
   enable_interrupts(INT_TIMER2);           // Enable Timer 2 Interrupt

   ext_int_edge(H_TO_L);          // init interrupt triggering for button press
   enable_interrupts(INT_EXT);    // turn on interrupts1
   enable_interrupts(GLOBAL);     // Enable Interrupts Global
   
   port_b_pullups(0x1F);          // Pullups on Keyboard Input Port
}

// === main ============================
void main()
{
   initialize();
   output_high(PIN_A0);
   
   output_e(0x00);
   output_c(0x00);
   
   while(TRUE)
   {
      if (!gIsSleeping)
      {                            // Awake
         output_high(PIN_A0);      // turn on radio
      }
      else
      {                            // Asleep
         output_low(PIN_A0);       // turn off radio
      }
     
      output_d(input_b());         // Send Data
      delay_ms(100);
   }
}
RLScott



Joined: 10 Jul 2007
Posts: 465

View user's profile Send private message

Re: Ext Interrupt only triggered on port B pin 0
PostPosted: Mon Sep 08, 2008 12:51 pm     Reply with quote

What you want is "Interrupt on Change". That is a different interrupt from INT_EXT. Also interrupt on change causes an interrupt when an enabled Port B pin changes in either direction. The external interrupt on RB0 only works in one direction.
_________________
Robert Scott
Real-Time Specialties
Embedded Systems Consulting
Ranfo



Joined: 08 Sep 2008
Posts: 38

View user's profile Send private message

PostPosted: Mon Sep 08, 2008 12:58 pm     Reply with quote

Thank you. Can you show me where I can find information on this?
meereck



Joined: 09 Nov 2006
Posts: 173

View user's profile Send private message

PostPosted: Mon Sep 08, 2008 1:05 pm     Reply with quote

simply:
Code:

#int_RB
void RB_isr()
{
   int8 current;
   static int8 last=0;
   current=input_b();

   if ((!bit_test(current,PIN_B0))&&(bit_test(last,PIN_B0))) {
// we have falling edge on B0
}
   last=current;
}


and enable global and RB interrupts:
Code:

enable_interrupts(INT_RB);
enable_interrupts(GLOBAL);
Ranfo



Joined: 08 Sep 2008
Posts: 38

View user's profile Send private message

PostPosted: Mon Sep 08, 2008 1:17 pm     Reply with quote

If I replace INT_EXT with INT_RB then the interrupt never triggers even on pin 0. I am still missing something.
Ranfo



Joined: 08 Sep 2008
Posts: 38

View user's profile Send private message

PostPosted: Mon Sep 08, 2008 1:28 pm     Reply with quote

OK, seems to be working now. Thank you all. Posting changes so others can see:

Code:

// === external interrupt =============
// #INT_EXT
#INT_RB
void ext_isr() {
   int8 n;
   n = input_b();

   gIsSleeping   = 0;
   gSleepcounter = 0;
}

// === Initialize =====================
void initialize() {
   setup_oscillator(OSC_31KHZ);

   setup_timer_2(T2_DIV_BY_16, 255, 1);     // Timer 2 (DIV_BY, Period, Post)
   enable_interrupts(INT_TIMER2);           // Enable Timer 2 Interrupt
   
   enable_interrupts(INT_RB0);
   enable_interrupts(INT_RB1);
   enable_interrupts(INT_RB2);
   enable_interrupts(INT_RB3);
   enable_interrupts(INT_RB4);
   enable_interrupts(GLOBAL);   

   port_b_pullups(0x1F);          // Pullups on Keyuboard Input Port
}
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