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

INT0 interrupt 18F242

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



Joined: 02 Jan 2006
Posts: 75
Location: Neeroeteren, Limburg, Belgium

View user's profile Send private message

INT0 interrupt 18F242
PostPosted: Mon Jan 02, 2006 6:56 am     Reply with quote

Hello,

At the moment i'm trying to generate an external interrupt on the PIC 18F24.

i want to generate the interrupt on pin RB0.
but it seems the interrupt is not catched...

the code i use is as below:

#include <18F242.H>
#fuses HS,NOWDT, NOPROTECT, PUT
#use DELAY (clock=20000000)

#use fast_io(A)
#use fast_io(B)

//int i;
//int x;
//int c;

#int_ext
void EXT_ISR()
{
output_high(PIN_A0);
delay_ms(200);
delay_ms(200);
delay_ms(200);
delay_ms(200);
delay_ms(200);
delay_ms(200);
output_high(PIN_A0);
}

/* main() */

void main()
{


/* Set pin A1 to be the blue led */
SET_TRIS_A(0x00);
/* Allow pin B0 to be an external interrupt pin */
SET_TRIS_B(0b00010000);

ext_int_edge(H_TO_L);
enable_interrupts(global);
enable_interrupts(int_rb);
while(1)
{
output_high(PIN_A3);
}
}



Greets,
Blob
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Mon Jan 02, 2006 8:39 am     Reply with quote

Code:
/* Allow pin B0 to be an external interrupt pin */
SET_TRIS_B(0b00010000);
You are configuring B4 as an input but your comment says B0.

Code:
#int_ext
void EXT_ISR()
{
output_high(PIN_A0);
delay_ms(200);
delay_ms(200);
delay_ms(200);
delay_ms(200);
delay_ms(200);
delay_ms(200);
output_high(PIN_A0);
}
Change one of the output_high() calls to output_low().
And why do you call 6 x delay_ms(200) when one call to delay_ms(1200) would do the same?
Humberto



Joined: 08 Sep 2003
Posts: 1215
Location: Buenos Aires, La Reina del Plata

View user's profile Send private message

PostPosted: Mon Jan 02, 2006 11:26 am     Reply with quote

Quote:

At the moment i'm trying to generate an external interrupt on the PIC 18F242.
i want to generate the interrupt on pin RB0.
but it seems the interrupt is not catched...


enable_interrupts(int_rb);
Should be
enable_interrupts(INT_EXT);

I assume you have a pull-up resistor wired from +5V to PIN RB0 or:
port_b_pullups(TRUE); declared in your code.

It is not a good practice to use delays inside an interrupt handler !!!

To 'see' the RB0 interrupt action, the following code should be enough.
(If your compiler version has the output_toggle() function.)

Code:

#int_ext
void EXT_ISR()
 {
  output_toggle(PIN_A0);
 }


or if it doesn't:

Code:

int8 ext_trigger;

#int_ext
void EXT_ISR()
 {
  output_high(PIN_A0);
  ext_trigger = TRUE;
 }

void main()
{
  while(1)
         {
           .......
           your stuff
           .......

           if(ext_trigger)
             {
               delay_ms(200);
               output_low(PIN_A0);
               delay_ms(200);
               ext_trigger = FALSE;
             }
         }
}



Best wishes,

Humberto
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