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 constantly triggering.

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



Joined: 22 Aug 2006
Posts: 18

View user's profile Send private message

Interrupt on change constantly triggering.
PostPosted: Thu Mar 08, 2007 10:05 am     Reply with quote

Hello,

I'm trying to detect a change on PIN_B4 but the interrupt is constantly triggering.
Can someone point out what I'm doing wrong?

Here is the code:
Code:


#include <18F4550.h>
#device adc=10
#IF  getenv("VERSION")>4.001
   #device ANSI
#ENDIF

#FUSES NOWDT                    //No Watch Dog Timer
#FUSES WDT128                   //Watch Dog Timer uses 1:128 Postscale
#FUSES HS                       //High speed Osc (> 4mhz)
#FUSES NOPROTECT                //Code not protected from reading
#FUSES NOBROWNOUT               //No brownout reset
#FUSES BORV20                   //Brownout reset at 2.0V
#FUSES NOPUT                    //No Power Up Timer
#FUSES NOCPD                    //No EE protection
#FUSES STVREN                   //Stack full/underflow will cause reset
#FUSES NODEBUG                  //No Debug mode for ICD
#FUSES NOLVP                    //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOWRT                    //Program memory not write protected
#FUSES NOWRTD                   //Data EEPROM not write protected
#FUSES IESO                     //Internal External Switch Over mode enabled
#FUSES FCMEN                    //Fail-safe clock monitor enabled
#FUSES PBADEN                   //PORTB pins are configured as analog input channels on RESET
#FUSES NOWRTC                   //configuration not registers write protected
#FUSES NOWRTB                   //Boot block not write protected
#FUSES NOEBTR                   //Memory not protected from table reads
#FUSES NOEBTRB                  //Boot block not protected from table reads
#FUSES NOCPB                    //No Boot Block code protection
#FUSES MCLR                     //Master Clear pin enabled
#FUSES LPT1OSC                  //Timer1 configured for low-power operation
#FUSES NOXINST                  //Extended set extension and Indexed Addressing mode disabled (Legacy mode)
#FUSES PLL1                     //No PLL PreScaler

#use delay(clock=20000000)
#use rs232(baud=9600,parity=N,xmit=PIN_D0,rcv=PIN_D1,bits=8, invert, STREAM=COM2)


void main(void)
{

   set_tris_b(0b00010000);
   //output_b(0x10) ;

   enable_interrupts( INT_RB );
   enable_interrupts( GLOBAL );

   while (1)
      ;
}


#INT_RB
void PortBChange_isr( void )
{
   set_tris_b(0x10);
   input_b();
   fprintf(COM2, "INTERRUPT\n");

}


I'm using V4.026.

Thanks for your help.

Christophe D.
Humberto



Joined: 08 Sep 2003
Posts: 1215
Location: Buenos Aires, La Reina del Plata

View user's profile Send private message

PostPosted: Thu Mar 08, 2007 10:22 am     Reply with quote

Try this way:

Code:

int interrupt_RB;

#INT_RB
void PortBChange_isr( void )
{
   input_b();
   interrupt_RB = TRUE;
}

void main(void)
{
   set_tris_b(0x10);
   enable_interrupts( INT_RB );
   enable_interrupts( GLOBAL );

   while (1)
      {
       if( interrutp_RB )
         {   
           fprintf(COM2, "INTERRUPT\n");
           interrupt_RB = FALSE;
         }
      }
}




Humberto
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Mar 08, 2007 10:35 am     Reply with quote

Quote:
#INT_RB
void PortBChange_isr( void )
{
set_tris_b(0x10);
input_b();
fprintf(COM2, "INTERRUPT\n");

}

The input_b() function won't actually read the port unless you load
it into a variable. You can see this in the .LST file.

Declare a local variable in that function and do this:
Code:

int8 c;

c = input_b();
ch_dupre



Joined: 22 Aug 2006
Posts: 18

View user's profile Send private message

PostPosted: Thu Mar 08, 2007 10:37 am     Reply with quote

Thanks Humberto and PCM programmer. Both solutions work.

Christophe D.
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