CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

#int_ext problem

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
cchappyboy



Joined: 03 Dec 2008
Posts: 45

View user's profile Send private message

#int_ext problem
PostPosted: Tue Jul 20, 2010 3:52 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Tue Jul 20, 2010 4:06 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Tue Jul 20, 2010 4:32 pm     Reply with quote

It works after I add clear_interrupt(int_ext);
Thank you so much
Ttelmah



Joined: 11 Mar 2010
Posts: 19506

View user's profile Send private message

PostPosted: Wed Jul 21, 2010 2:24 am     Reply with quote

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

View user's profile Send private message

PostPosted: Thu Jul 22, 2010 10:00 am     Reply with quote

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!
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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