|
|
View previous topic :: View next topic |
Author |
Message |
Vinoth Guest
|
#INT_EXT Not Working |
Posted: Mon May 04, 2009 10:25 pm |
|
|
Hi All
i am Beginner for PIC MCU. I Need to use 16f887 PIn B0 as a External Interrupt.
am using CCS C Compiler.initially I Configured Port B 0 as INPUT Pin in Project Wizard.
this are the codes i Used( Its a very Basic Thing)..
#int_EXT
int8 a=0xaa,b=0xaa;
void delay();
void EXT_isr(void)
{
delay();
output_high(PIN_E2);
clear_interrupt(INT_EXT);
a=0xf0;
delay();
b=0x0f;
delay();
}
void main()
{
setup_adc_ports(NO_ANALOGS|VSS_VDD);
setup_adc(ADC_OFF);
setup_spi(SPI_SS_DISABLED);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_comparator(NC_NC_NC_NC);// This device COMP currently not supported by the PICWizard
enable_interrupts(INT_EXT);
enable_interrupts(GLOBAL);
ext_int_edge( L_TO_H );
setup_oscillator(OSC_8MHZ);
// TODO: USER CODE!!
output_c(0x01);
output_d(0xC0);
output_LOW(PIN_E0);
output_HIGH(PIN_E1);
output_low(PIN_E2);
output_HIGH(PIN_B1);
output_HIGH(PIN_B2);
output_HIGH(PIN_B4);
output_HIGH(PIN_B5);
while(1)
{
output_c(a);
delay();
output_c(b);
delay();
}
}
void delay()
{
int16 i,a=1,b=0;
for(i=0;i<=40000;i++)
b=a+i;
}
BuT Am Facing problem tat The Device Not Jumbing to the Interupt routine
..wen there is low to high transition... its still looping inside the Main..
It Seems My Code HAving Some Problems in Defining tat.. But I Cant identify Which is the Probelm
AnyOne Can Help Me On tHis...Plzzz
Thanks in ADVANCE
|
|
|
Vinoth Guest
|
#INT_EXT Not Working |
Posted: Mon May 04, 2009 11:53 pm |
|
|
This is the Code
Code: |
#int_EXT
int8 a=0xaa,b=0xaa;
void delay();
void EXT_isr(void)
{
delay();
output_high(PIN_E2);
clear_interrupt(INT_EXT);
a=0xf0;
delay();
b=0x0f;
delay();
}
void main()
{
setup_adc_ports(NO_ANALOGS|VSS_VDD);
setup_adc(ADC_OFF);
setup_spi(SPI_SS_DISABLED);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_comparator(NC_NC_NC_NC);// This device COMP currently not supported by the PICWizard
enable_interrupts(INT_EXT);
enable_interrupts(GLOBAL);
ext_int_edge( L_TO_H );
setup_oscillator(OSC_8MHZ);
// TODO: USER CODE!!
output_c(0x01);
output_d(0xC0);
output_LOW(PIN_E0);
output_HIGH(PIN_E1);
output_low(PIN_E2);
output_HIGH(PIN_B1);
output_HIGH(PIN_B2);
output_HIGH(PIN_B4);
output_HIGH(PIN_B5);
while(1)
{
output_c(a);
delay();
output_c(b);
delay();
}
}
void delay()
{
int16 i,a=1,b=0;
for(i=0;i<=40000;i++)
b=a+i;
}
|
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue May 05, 2009 12:08 am |
|
|
Your program is too complex. Look at this simple program first.
Every time an external interrupt on Pin B0 occurs, pin B1 will change
state. This program assumes that you have a clean input signal on
pin B0, and that the signal frequency is less than 10 KHz.
Code: |
#include <16F887.h>
#fuses INTRC_IO,NOWDT,BROWNOUT,PUT,NOLVP
#use delay(clock = 4000000)
#INT_EXT
void ext_isr(void)
{
output_toggle(PIN_B1);
}
//=======================
void main()
{
output_low(PIN_B1); // Initially set Pin B1 low
ext_int_edge(L_TO_H);
clear_interrupt(INT_EXT);
enable_interrupts(INT_EXT);
enable_interrupts(GLOBAL);
while(1);
} |
|
|
|
bungee-
Joined: 27 Jun 2007 Posts: 206
|
|
Posted: Tue May 05, 2009 1:22 am |
|
|
@Vinoth: Do not use delay inside ISR. That is bad practice! |
|
|
Vinoth Guest
|
#INT_EXT Not Working |
Posted: Tue May 05, 2009 1:38 am |
|
|
Hi
Thank you Very Much For Ur Fast Reply..
I didnt used the clear input...it may be the Problem.
Now its Working Properly..
Thanks a Lot
Thank U Very muchhhh |
|
|
doguhanpala
Joined: 05 Oct 2016 Posts: 120
|
|
Posted: Fri Oct 14, 2016 6:24 am |
|
|
i use this code
Code: | #include <18F2550.h>
#fuses INTRC_IO, HS, NOWDT, PUT, NOLVP,NOMCLR,NOPROTECT,NOLVP,NODEBUG,NOBROWNOUT,USBDIV,CPUDIV1,VREGEN,NOPUT
#device ADC=10
#use delay(clock=4000000)
#int_EXT
void external_interrupt_isr()
{
output_high(PIN_A5); //open interrupt led
}
void main()
{
//setup lines
set_tris_b(0b1); // i use this pin for interrupt. button switch goes to B0 since i use int_EXT
ext_int_edge(L_TO_H);
setup_oscillator(OSC_4MHZ);
ENABLE_INTERRUPTS(INT_EXT);
ENABLE_INTERRUPTS(GLOBAL);
while(TRUE)
{
output_low(PIN_A5); //close the interrupt led
output_high(PIN_A0); //blink led1
delay_ms(500);
output_low(PIN_A0);
delay_ms(500);
}
}
|
but when i change the code from inx_EXT to int_EXT1 it doesnt work. (i change the input connections to B1 pin of course) do you have any idea what is wrong on my code? |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19552
|
|
Posted: Fri Oct 14, 2016 7:10 am |
|
|
#INT_EXT, should be the line before the function declaration. No spaces, delay's, variables etc.
The compiler will let you get away with 'whitespace', but anything else can cause problems.
In your original code, you are actually declaring the 'delay' function to be the handler for the interrupt.
Their example in the manual, is pretty clear:
Code: |
#int_ad
adc_handler() {
adc_active=FALSE;
}
#int_rtcc noclear
isr() {
...
}
|
Also look at the examples.
To change to INT_EXT1, remember you also need to change the TRIS.
In fact if you didn't have the TRIS line it'd work (the compiler will handle this automatically), but you are explicitly saying that only B0 is an input..... |
|
|
doguhanpala
Joined: 05 Oct 2016 Posts: 120
|
|
Posted: Fri Oct 14, 2016 7:36 am |
|
|
Ttelmah wrote: | #INT_EXT, should be the line before the function declaration. No spaces, delay's, variables etc.
The compiler will let you get away with 'whitespace', but anything else can cause problems.
In your original code, you are actually declaring the 'delay' function to be the handler for the interrupt.
Their example in the manual, is pretty clear:
Code: |
#int_ad
adc_handler() {
adc_active=FALSE;
}
#int_rtcc noclear
isr() {
...
}
|
Also look at the examples.
To change to INT_EXT1, remember you also need to change the TRIS.
In fact if you didn't have the TRIS line it'd work (the compiler will handle this automatically), but you are explicitly saying that only B0 is an input..... |
First of all, i thank you very much. I changed the code as you said. There are no space between int_EXT1 and void internal input lines (i checked). I removed the tris line.
Code: | #int_EXT1
void external_interrupt_isr()
{
output_high(PIN_A5); //open interrupt led
}
void main()
{
//setup lines
ext_int_edge(L_TO_H);
setup_oscillator(OSC_4MHZ);
ENABLE_INTERRUPTS(INT_EXT);
ENABLE_INTERRUPTS(GLOBAL);
while(TRUE)
{
output_low(PIN_A5); //close the interrupt led
output_high(PIN_A0); //blink led1
delay_ms(500);
output_low(PIN_A0);
delay_ms(500);
}
}
|
Still doesn't work.
I want to use 2 interrupts at the same time.
Like this:
Code: |
#int_EXT
void external_interrupt_B0_isr()
{
STATUS_FLAG1=1;
OUTPUT_HIGH(PIN_A0);
}
//Interrupt Fonksiyonu 2 (B1 pini interruptı)
#int_EXT1
void external_interrupt_B1_isr()
{
STATUS_FLAG2=1;
OUTPUT_HIGH(PIN_A5);
} |
I tried to open leds to see flag is 1 on or not. But one of the leds did not work and my code did not work either. I checked the inputs and saw the problem. int_EXT1 was not working. I connected each of my optical encoders to B0 pin and used int_EXT to see if encoders are working. They are.
So i returned my basic interrupt code to see how can i make the b1 or b2 pin interrupts work. I know i use the delay and when my code tries to close the led it has to wait for delays. Since the code is for test, i don't mind.
Unfortunately, with the last edit, the code does not work. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19552
|
|
Posted: Fri Oct 14, 2016 9:20 am |
|
|
You are enabling INT_EXT, not INT_EXT1.
You really do need to think. Details are everything.
To use INT_EXT1, INT_EXT1 needs to be enabled....
Also, you are not actually setting the edge for this interrupt.
ext_int_edge(L_TO_H);
Sets the edge for int 0 (EXT_INT).
To set it for INT1, you need:
ext_int_edge(1,L_TO_H); |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19552
|
|
Posted: Fri Oct 14, 2016 10:46 am |
|
|
As another comment:
setup_spi(SPI_SS_DISABLED);
is also wrong. This _enables_ the SPI, and disables slave select on it. To disable the SPI, the syntax is:
setup_spi(FALSE);
This is a common error. |
|
|
|
|
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
|