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

Simple RB0 interrupt (#int_ext)

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








Simple RB0 interrupt (#int_ext)
PostPosted: Thu May 12, 2005 6:12 pm     Reply with quote

I am learning PIC C, I try to work with external interrupt. I can't not get it to work. Can any body help?

here is my code:
Code:

#include <18F452.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=20000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)  // Jumpers: 8 to 11, 7 to 12

/*
   *LED connect to RB1 is active low (0=ON, 1=OFF)

*/
            //Start interrupt subroutine.
#int_ext       //Set external interrupt on pin RB0
void ISR()
{
   output_low(pin_b1); // when RB0 is low turn on LED

}

// End Interrupt routine


//Main program start here

void main()
{
   output_b(0x00);
   set_tris_b(0x01);      // Set RB0 to input, RB1-7 output

   ext_int_edge(H_TO_L);      // init interrupt triggering for button press
   enable_interrupts(INT_EXT);
   enable_interrupts(GLOBAL);

   
   while (1)    // keep LED off.
   {   
    output_high(pin_b1);
    }
}


I am looking forward to hear from soon.
Thanks....
iso9001



Joined: 02 Dec 2003
Posts: 262

View user's profile Send private message

PostPosted: Thu May 12, 2005 9:24 pm     Reply with quote

You are going back to the while() and then the output_high so fast I'm guessing you are just not seeing it.

Holding the int pin low will not hold the LED on if that is what you were thinking.

try

Code:

void main()
{
   output_b(0x00);
   set_tris_b(0x01);      // Set RB0 to input, RB1-7 output

   ext_int_edge(H_TO_L);      // init interrupt triggering for button press
   enable_interrupts(INT_EXT);
   enable_interrupts(GLOBAL);

   output_high(pin_b1);
   while (1)    // keep LED off.
   {   
   
    }
}


With that the led should turn on when the int is driven low.
Guest








Interrupt
PostPosted: Mon May 16, 2005 10:41 am     Reply with quote

I have tried that and it does not respond to the RBO sw. When the sw=0,
it does not turn on the LED on pin_b1. Anyone has a sample code for interrupt to do this simple interrupt? I have read the example came with
the manual, but I do not get it, I am may be too new to PIC.

Please help.....
John P



Joined: 17 Sep 2003
Posts: 331

View user's profile Send private message

PostPosted: Mon May 16, 2005 11:48 am     Reply with quote

Try adding a delay to the interrupt so it has time to let you see the light before returning to the main program. See addition:

Code:

#include <18F452.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=20000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7) // Jumpers: 8 to 11, 7 to 12

/*
  *LED connect to RB1 is active low (0=ON, 1=OFF)

*/
        //Start interrupt subroutine.
#int_ext     //Set external interrupt on pin RB0
void ISR()
{
  output_low(pin_b1); // when RB0 is low turn on LED

  delay_ms(200); // Wait 0.2 second with light on before returning

}

// End Interrupt routine


//Main program start here

void main()
{
  output_b(0x00);
  set_tris_b(0x01);    // Set RB0 to input, RB1-7 output

  ext_int_edge(H_TO_L);   // init interrupt triggering for button press
  enable_interrupts(INT_EXT);
  enable_interrupts(GLOBAL);

 
  while (1)   // keep LED off.
  { 
  output_high(pin_b1);
  }
}
iso9001



Joined: 02 Dec 2003
Posts: 262

View user's profile Send private message

PostPosted: Mon May 16, 2005 11:49 am     Reply with quote

Exactly, When I posted I only posted the part you needed to change, and even then it was a single shot switch,
sseidman



Joined: 14 Mar 2005
Posts: 159

View user's profile Send private message

PostPosted: Mon May 16, 2005 1:38 pm     Reply with quote

John P wrote:
Try adding a delay to the interrupt so it has time to let you see the light before returning to the main program.


Putting 200ms delays in interrupt routines is a habit best left undeveloped.

Scott
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon May 16, 2005 1:43 pm     Reply with quote

There is a complete demo program for INT_EXT in this thread:
http://www.ccsinfo.com/forum/viewtopic.php?t=8504
Guest








interrupt
PostPosted: Mon May 16, 2005 2:43 pm     Reply with quote

Thanks....

I got it working, somehow the SW on RB0 of my demo 2 plus board does
not work, that's why I didn't see it. But actually the software is working fine.
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