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 support@ccsinfo.com

Question! External interrupt in PIC12F675

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







Question! External interrupt in PIC12F675
PostPosted: Sun May 29, 2005 10:18 pm     Reply with quote

I'm just a beginner with C, so please don't be too hard on me regarding my style!

The code below does try to work. And I use the CCS-C compiler and PIC12F675.
The problem is the external interrup in PIC12F675.
I want to control the LED with PIC12F675, but the external interrupt don't operate.

What could be causing this?

=================================
#include <12f675.h>

#fuses INTRC,NOWDT,NOCPD,PROTECT,NOMCLR
#fuses NOPUT,NOBROWNOUT
#use delay (clock=4000000)
#use fixed_io(a_outputs=pin_a0, pin_a1)
#byte porta=0x06
#byte intcon=0x0b
#bit INTF=INTCON.1

#int_ext
ext_isr()
{
INTF=0;
output_bit(PIN_A0,1);
}

void main(void)
{
ext_int_edge(0,L_to_H);
enable_interrupts(INT_EXT);
enable_interrupts(GLOBAL);

while(true)
{
output_bit(PIN_A0,0);
}
}


[/b]
Ttlemah
Guest







PostPosted: Mon May 30, 2005 5:20 am     Reply with quote

First comment, you don't need to clear the interrupt flag in the handler. The compiler will do this for your, unless the 'noclear' option is used in the definition. It doesn't 'matter', but is an unecessary instruction.
The same applies to the ext_int_edge definition, on the 12675, with only one interrupt, you just need:
ext_int_edge(L_to_H);
You won't see an LED operate with the code as shown. The interrupt will set the bit on, but as soon as the interrupt exits, the main loop will clear it. The LED will light for a few uSec only, which unless the interrupt if being triggered at a frequent interval, will not be enough to be visible.
Rewrite the main loop with:
Code:

while (true) {
   if (input(PIN_A0)) {
      delay_ms(10);
      output_low(PIN_A0);
   }
}


This way the LED will light for 10mSec (plus the interrupt return time), when triggered.

Best Wishes
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