View previous topic :: View next topic |
Author |
Message |
Sigma
Joined: 03 May 2004 Posts: 48 Location: Sg
|
need help on external interrupt for PIC16C63A |
Posted: Fri Sep 22, 2006 11:19 pm |
|
|
Hi, all,
I could not have external interrupt triggered on my ICE2000 emulating 16C63A. I have a 10K resistor pull high on RB0. And a on/off switch to ground.
Code: |
#include <16C63A.h>
#fuses HS,NOWDT,NOPROTECT,PUT,NOBROWNOUT
#use delay(clock=8000000)
#INT_EXT
void ext_ISR()
{
output_low(PIN_A1); //Breakpoint set here, but not triggered when switch is tied to ground
}
void main()
{
port_b_pullups(TRUE); //Port B weak pullup
ext_int_edge(H_to_L); //External interrupt edge from high to low
enable_interrupts(INT_EXT);
clear_interrupt(INT_EXT);
enable_interrupts(GLOBAL);
while(1)
{
if(input(PIN_B0)==0)
{
output_high(PIN_A1);
}
}
}
|
I am using PCM 4.010
thanks.
Sigma |
|
|
Humberto
Joined: 08 Sep 2003 Posts: 1215 Location: Buenos Aires, La Reina del Plata
|
|
Posted: Sat Sep 23, 2006 3:27 pm |
|
|
After RESET - by default - ALL pins that share an Analog function are configured as Analog INPUTS.
During the initialisation part of your code, disable the Analog function:
Code: |
port_b_pullups(TRUE); //Port B weak pullup
ext_int_edge(H_to_L); //External interrupt edge from high to low
enable_interrupts(INT_EXT);
clear_interrupt(INT_EXT);
enable_interrupts(GLOBAL);
SETUP_ADC_PORTS(NO_ANALOG); // ********Add this ********
|
Humberto |
|
|
hate
Joined: 29 Apr 2006 Posts: 6
|
|
Posted: Sat Sep 23, 2006 4:41 pm |
|
|
How did you get the idea that the interrupt isn't triggered? By checking the Pin A1? In the ext_ISR you make the A1 pin go low but in the main function you make it high when the B0 pin goes low. Your code triggers the interrupt when the B0 pin goes low so both the interrupt and the if() code gets active by the same event. And they both act on the pin B0 going low. So the ISR makes the pin A1 go low then immediately after exiting the interrupt the if statement makes the A1 pin go high. If you don't have a very slow clock speed it is not much possible to see the change. And my guess is that you get the idea that the intterupt isn't triggered.
Regards... |
|
|
Humberto
Joined: 08 Sep 2003 Posts: 1215 Location: Buenos Aires, La Reina del Plata
|
|
Posted: Sun Sep 24, 2006 8:31 am |
|
|
Quote: |
How did you get the idea that the interrupt isn't triggered? By checking the Pin A1?
|
I´m agree with you that this may be not the best example to see the INT_EXT
action but it should work anyway.
The signal received by PIN_B0 causes a temporary halt in the execution of the main
program (wich is to keep the PIN_A1 HIGH while PIN_B0 is HIGH) so the task is
re-directed to the interrupt handler that will keep PIN_A1 LOW as long as PIN_B0
is LOW. When the interrupt had been serviced, the program return to main in
the last instruction + 1 to follow it´s main task, that is to keep PIN_A1 HIGH ONLY
while PIN_B0 is HIGH, but as PIN_B0 is still LOW, the interrupt is triggered again and
by no way the PIN_A1 will go HIGH while PIN_B0 stay LOW.
Quote: |
Your code triggers the interrupt when the B0 pin goes low so both the interrupt and the if() code gets active by the same event.
|
The posted code do not do that. The if() condition does nothing when PIN_B0 is LOW.
Humberto |
|
|
hate
Joined: 29 Apr 2006 Posts: 6
|
|
Posted: Mon Sep 25, 2006 2:59 pm |
|
|
Hi Humberto;
I think you have to check the code again to see the if() statement in the main loop will repeatedly check for "B0 pin" to get low(0) and then make the "A1 pin" high(1) when "B0 pin" gets low(0). So that's the same event that triggers the interrupt. Are we clear on that? The interrupt will get triggered only ONCE when the B0 pin gets LOW(0) as it isn't LEVEL triggered like the Externel Interrupts of 8051 structure. And it WON'T get triggered again if the "B0 pin" is low and until it goes high(1) and low(0) again as it is EDGE triggered. When after the ISR finishes its work the program will continue executing the while loop in the main function and the if() statement. He said he uses a switch on the "B0 pin" so the pin will probably be at logic low(0) state which is TRUE for the if() statement and the "A1 pin" will go high(1) immediately after existing the ISR. Correct me if I'm wrong. Best wishes.
Regards... |
|
|
Humberto
Joined: 08 Sep 2003 Posts: 1215 Location: Buenos Aires, La Reina del Plata
|
|
Posted: Mon Sep 25, 2006 4:09 pm |
|
|
My mistake, I never use such notation:
Code: |
if(input(PIN_B0)==0)
{
}
|
Instead I use
Code: |
if(!input(PIN_B0))
{
}
|
so I assume he was testing for HIGH.
Sorry
Humberto |
|
|
|