Jump to content
Sign in to follow this  
ddr

Interrupt In 18f252

Recommended Posts

I'm trying to get interrupts to work (both HIGH/LOW priority as well as compatibility mode). I'm using sourceboost ide 5.8 with boostc toolset. Boostc appears to be the only toolset to support 18f252.

 

I'm folloing the 18f252 pdf from micochip. Here is what I do:

 

define a function called "void interrupt (void)" which toggles a led. I also clear int3con,int1if and int3con,int2if in the "void interrupt (void)" isr.

 

In main, I:

- set intcon2,intedg1

- set intcon2,intedg2

- clear int3con, in2ip

- clear int3con, in1ip

- set int3con,int2ie

- set int3con,int1ie

- clear int3con,int1if

- clear int3con,int1if

- clear rcon,,ipen

- set intcon,gie

- set intcon,gieh

 

I compile and program the PIC. Then I trigger int1 and it appears to work once. Then either the PIC goes off in never never land or a second int1 trigger does not work.

 

Is there something I'm missing? Do I need to do something to trigger the interrupt a second time.

Share this post


Link to post
Share on other sites

SourceBoost PIC18 simulator doesn't support interrupts for PIC18 targets (yet). You'll need to run your code on real target to check this.

 

Regards,

Pavel

Share this post


Link to post
Share on other sites

SourceBoost PIC18 simulator doesn't support simulated I/O for PIC18 targets either.

 

Have you tried the PIC18 interrupt example code supplied with the SourceBoost Package?

 

 

Regards

Dave

Share this post


Link to post
Share on other sites

Thanks guys. I'm not interested in using the simulator just the boostc compiler.

 

The sample is based on

 

How do I code Maybe I'm missing something. Please explain.

 

Here is the code I'm running:

 

 

#include <boostc.h>

 

#include <system.h>

 

#define ON 0x0

#define OFF 0x1

 

char flag;

 

void blink ( unsigned char dly, char off )

{

clear_bit (latb, RB7);

delay_ms (dly);

set_bit (latb, RB7);

delay_ms (dly);

if (off) clear_bit (latb, RB7);

}

 

void interrupt ( void )

{

if ( intcon3&INT1IE && intcon3&INT1IF ) {

set_bit (latb, RB7);

clear_bit (intcon3, INT1IF);

flag = 0x1;

set_bit (intcon3, INT2IE); // Enable Int

}

 

if ( intcon3&INT2IE && intcon3&INT2IF ) {

clear_bit (latb, RB7);

clear_bit (intcon3, INT2IF);

flag = 0x1;

}

 

}

 

void main ()

{

 

clear_bit (trisb, RB7);

clear_bit (latb, RB7);

 

 

set_bit (trisb, RB1);

set_bit (trisb, RB2);

clear_bit (latb, RB1);

clear_bit (latb, RB2);

 

set_bit (intcon2, INTEDG1); // Enable rising edge Int

set_bit (intcon2, INTEDG2); // Enable rising edge Int

 

set_bit (intcon3, INT2IE); // Enable Int

set_bit (intcon3, INT1IE); // Enable Int

 

clear_bit (intcon3, INT1IF); // Clear Int Flags

clear_bit (intcon3, INT2IF); // Clear Int Flags

 

clear_bit (intcon3, INT2IP); // Disable Priority Int

clear_bit (intcon3, INT1IP); // Disable Priority Int

 

blink (250, OFF);

blink (250, OFF);

flag = 0x1;

 

clear_bit (rcon, IPEN); // Disable Global Priority Int

clear_bit (intcon, PEIE); // Disable Peripheral Int

set_bit (intcon, GIE); // Enbable Global Int

 

while (1) {

if (flag) blink (250,OFF);

else nop();

}

}

Share this post


Link to post
Share on other sites

ddr,

 

Your example looks fine, but it is a little complex, I would recommend simplfying it so you only have one source of interrupt for a start.

 

Also please have a look as the timer interrupt sample project (interrupt.__c) that is in the sample folder in the installation directory.

 

This sample code works.

 

Regards

Dave

Share this post


Link to post
Share on other sites

Join the conversation

You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...