| View previous topic :: View next topic |
| Author |
Message |
Guest
|
| Simple RB0 interrupt (#int_ext) |
Posted: Thu May 12, 2005 6:12 pm |
|
|
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
|
|
Posted: Thu May 12, 2005 9:24 pm |
|
|
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 |
Posted: Mon May 16, 2005 10:41 am |
|
|
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
|
|
Posted: Mon May 16, 2005 11:48 am |
|
|
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
|
|
Posted: Mon May 16, 2005 11:49 am |
|
|
| 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
|
|
Posted: Mon May 16, 2005 1:38 pm |
|
|
| 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
|
|
 |
Guest
|
| interrupt |
Posted: Mon May 16, 2005 2:43 pm |
|
|
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. |
|
 |
|