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

Need help in RB0 external interrupt

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



Joined: 08 Nov 2004
Posts: 11

View user's profile Send private message

Need help in RB0 external interrupt
PostPosted: Wed Nov 10, 2004 3:26 am     Reply with quote

Code:

#include <16f877a.h>
#fuses HS,NOLVP,NOWDT,PUT
#use delay(clock=20000000)

int1 found_it;

#int_ext
void ext_isr()
{
   found_it = true;
}

void main()
{
   found_it = false;
   set_tris_b(0x01);

   enable_interrupts(global);    // set GIE in INTCON register
   enable_interrupts(int_ext);   // set INTE in INTCON register

   ext_int_edge(H_TO_L);    // initially RB0 is high (button is not pressed)
                                        // clear INTEDG in OPTION_REG register
   while(TRUE)
   {
      if (found_it)
      {
         found_it = false;
         output_high(PIN_D1);
         delay_ms(2000);
      }

      output_high(PIN_D1);
      delay_ms(300);
      output_low(PIN_D1);
      delay_ms(300);
   }
}


I write this for RB0 interrupt but it don't work. I have studied the datasheet and follow the requirement. Is there any important point I miss out? Anyone can help me? THX!
Juan Pablo
Guest







Problem with RB0 interrupt
PostPosted: Wed Nov 10, 2004 5:34 am     Reply with quote

Try putting the next lines of code in this order:

...
ext_int_edge(H_to_L);
enable_interrupts(INT_EXT);
enable_interrupts(GLOBAL);
...

Best Wishes.
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Wed Nov 10, 2004 5:45 am     Reply with quote

Have you checked the voltage levels on input pin_B0? Are they 5V with switch open and 0V with the switch closed?

Please note that by default the internal pull-up resistors on port-b are disabled, so you either need external pull-up resistors or use PORT_B_PULLUPS(TRUE) for enabling the internal pull-ups.
Twitie



Joined: 08 Nov 2004
Posts: 11

View user's profile Send private message

PostPosted: Thu Nov 11, 2004 7:58 pm     Reply with quote

My port RB0 is initially high(5V). It turns to low when I press the button. I have set the port_b_pullups but still cannot work... Crying or Very sad

Code:

........
   found_it = false;
   set_tris_b(0x01);
   
   ext_int_edge(H_TO_L);
   enable_interrupts(int_ext);
   enable_interrupts(global);
   
   port_b_pullups(TRUE);
.......
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Nov 11, 2004 8:31 pm     Reply with quote

This thread has a demo program for INT_EXT.
http://www.ccsinfo.com/forum/viewtopic.php?t=8504
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Thu Nov 11, 2004 8:38 pm     Reply with quote

You don't have anything else attached to portb do you? Namely RB0? I tried an experiment with a PICDEM2 Plus board. RB0 has an LED on it along with RB3-RB1. I wanted to use one of the another LEDs but enabling the LEDs with the jumper caused a problem. Otherwise, the code worked fine and I got the int.
Twitie



Joined: 08 Nov 2004
Posts: 11

View user's profile Send private message

PostPosted: Thu Nov 11, 2004 8:56 pm     Reply with quote

Quote:

You don't have anything else attached to portb do you? Namely RB0? I tried an experiment with a PICDEM2 Plus board. RB0 has an LED on it along with RB3-RB1. I wanted to use one of the another LEDs but enabling the LEDs with the jumper caused a problem. Otherwise, the code worked fine and I got the int.


Do you mean that all the portb pins should be 'free'? I connect my RB0 to a button (initially open) and my RD1 to a LED.
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Thu Nov 11, 2004 9:58 pm     Reply with quote

Quote:
Do you mean that all the portb pins should be 'free'?


No, just RB0
Twitie



Joined: 08 Nov 2004
Posts: 11

View user's profile Send private message

PostPosted: Thu Nov 11, 2004 10:35 pm     Reply with quote

I connect my RB0 to a normally-open push button. This connection is correct right?

................ __
RB0 --------o o-------- Gnd
............push buttton


and I internally pull port b to high using "port_b_pullups(TRUE);" and clear the INTEDG using "ext_int_edge(H_TO_L);".

Since you have tested my code and it is working.... I think I have to check my circuit.
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