View previous topic :: View next topic |
Author |
Message |
Twitie
Joined: 08 Nov 2004 Posts: 11
|
Need help in RB0 external interrupt |
Posted: Wed Nov 10, 2004 3:26 am |
|
|
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 |
Posted: Wed Nov 10, 2004 5:34 am |
|
|
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
|
|
Posted: Wed Nov 10, 2004 5:45 am |
|
|
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
|
|
Posted: Thu Nov 11, 2004 7:58 pm |
|
|
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...
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
|
|
|
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Thu Nov 11, 2004 8:38 pm |
|
|
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
|
|
Posted: Thu Nov 11, 2004 8:56 pm |
|
|
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
|
|
Posted: Thu Nov 11, 2004 9:58 pm |
|
|
Quote: | Do you mean that all the portb pins should be 'free'? |
No, just RB0 |
|
|
Twitie
Joined: 08 Nov 2004 Posts: 11
|
|
Posted: Thu Nov 11, 2004 10:35 pm |
|
|
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. |
|
|
|