View previous topic :: View next topic |
Author |
Message |
cchappyboy
Joined: 03 Dec 2008 Posts: 45
|
#int_ext problem |
Posted: Tue Jul 20, 2010 3:52 pm |
|
|
I use pic16f84a pin6 that is RB0 as ext interrupt.
Part of my program:
Code: |
int1 ext_status=0;
#int_ext
void extisr()
{
ext_status=1;
}
void main()
{
ext_status=0;
ext_int_edge(L to H);
enable_interrupts(int_ext);
enable_interrupts(global);
output_low(pin_a1);
while(true)
{
if(ext_status)
{
output_high(pin_a1);
}
do somethingelse.......
}
}
|
Actually there is no L to H on the pin6. But every time I give power to the chip the pin_a1 output high. It looks the int_ext interrupt server program has been executed.
I don't know why. Is there something I missed. Please give me a help!!!
Thanks |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Jul 20, 2010 4:06 pm |
|
|
Quote: |
Actually there is no L to H on the pin6.
|
Is there a pull-up resistor on that pin, so it's not floating ?
You need a pull-up to hold the pin at a "logic high" level so it
won't trigger on noise. You can use a 4.7K ohm resistor.
Also, clear the interrupt flag before you enable global interrupts.
Add the line shown in bold below:
Quote: |
ext_int_edge(L to H);
enable_interrupts(int_ext);
clear_interrupt(INT_EXT);
enable_interrupts(global);
|
|
|
|
cchappyboy
Joined: 03 Dec 2008 Posts: 45
|
|
Posted: Tue Jul 20, 2010 4:32 pm |
|
|
It works after I add clear_interrupt(int_ext);
Thank you so much |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19506
|
|
Posted: Wed Jul 21, 2010 2:24 am |
|
|
As an explanation of 'why', look in the data sheet.
Whenever you change the interrupt detection 'edge' (L_TO_H), you can trigger the interrupt. Hence if you want to change this in your code, you should:
1) Ensure interrupts are disabled before changing it (doesn't apply at startup).
2) Change the edge.
3) Clear the interrupt - in case it has triggered.
4) Enable the interrupt
Best Wishes |
|
|
cchappyboy
Joined: 03 Dec 2008 Posts: 45
|
|
Posted: Thu Jul 22, 2010 10:00 am |
|
|
Thank you very much for you response and I have few questions here
1) Ensure interrupts are disabled before changing it (doesn't apply at startup).
what is that mean 'changing it' .
3) Clear the interrupt - in case it has triggered.
This should be put into interrupt service program?
4) Enable the interrupt
is that mean i should re_enable it after very interrupt?
where should I enable it.
Thanks again! |
|
|
|