Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Problem in External interrupt(INTE)

Status
Not open for further replies.

vinay bs

Member level 3
Joined
May 22, 2012
Messages
65
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
1,751
Hi,

I am using pic 16f676 and mikroc compiler, i facing problem in external interrupt(INTE), interrupt occurs at first time
and next time onwards its not responding, below is my code, please help me out wats wrong with my program.....

thanks in advance...

Code:
#define red PORTC.F0
#define green PORTC.F1
#define blue PORTC.F2
#define mode PORTA.F2

void flashrgb();
void strobe();
void smooth();
void fadergb();
void rgboff();
unsigned char i,j,k,l,m,n;
unsigned int count,sec;
unsigned int signal_high;
unsigned int signal_low;
unsigned char readb;
unsigned char mode_count = 0;

void interrupt()
{

  if(INTCON.INTF == 1)
  {
     mode_count = mode_count+1;
     switch(mode_count)
     {
        case 1:
        INTCON.INTF = 0;
        flashrgb();
        break;
      
        case 2:
        INTCON.INTF = 0;
        strobe();
        break;
      
        case 3:
        INTCON.INTF = 0;
        fadergb();
        break;
   
        case 4:
        INTCON.INTF = 0;
        mode_count = 0;
        smooth();
        break;
     }
     INTCON.INTF = 0;
  }
}

void main()
{
 OPTION_REG = 0b00000000;
 WPUA = 0b00000100;
 INTCON.GIE = 1;
 //INTCON.PEIE = 1;
 INTCON.INTE = 1;
 INTCON.INTF = 0;
 CMCON = 0x07;
 ANSEL = 0x00;
 TRISA = 0b111111;
 TRISC = 0b000000;
 PORTC = 0x00;
  
  while(1)
  {
    INTCON.INTF = 0;
    rgboff();
  }
}

void rgboff()
{
  red=0;
  green=0;
  blue=0;
}

void fadergb()
{
  
}

void flashrgb()
{
  
}

void strobe()
{
  
}

void smooth()
{
  
}
 

hello


You don't need to clear the flag at every step.
Let the called subroutine to do his job, so no interrupt during this time
and after, clear the flag

but it's also depend what you will put insides subroutines !!!

Code:
void interrupt()
{

  if(INTCON.INTF == 1)
  {
     mode_count = mode_count+1;
     switch(mode_count)
     {
        case 1:
        flashrgb();
        break;
      
        case 2:
         strobe();
        break;
      
        case 3:
         fadergb();
        break;
   
        case 4:
         mode_count = 0;
        smooth();
        break;
     }
     INTCON.INTF = 0;
  }
}

void main()
{
 OPTION_REG = 0b00000000;
 WPUA = 0b00000100;
 INTCON.GIE = 1;
 //INTCON.PEIE = 1;
 INTCON.INTE = 1;
 INTCON.INTF = 0;
 CMCON = 0x07;
 ANSEL = 0x00;
 TRISA = 0b111111;
 TRISC = 0b000000;
 PORTC = 0x00;

//  init the value 
mode_count=0;

  
  while(1)
  {
    INTCON.INTF = 0;
    rgboff();  // why don't include in the sequencer ?
   // add here some delay to get a chance to have interrupt flag ON 
   delay_ms(100);
  }
}
 

hi paulfjujo,
i need port a pin2(RA2) acts like a switch, i.e when i pressed mode pin RA2 case 1:flashrgb() routine has to be execute....
next if i press same mode pin again it has to execute next sub routine case 2:strobe ...
like wise 4 modes.....after 4th mode next it should to take 1st one.... so i am using external interrupt.....
but its(interrupt occur) operating only for first mode, after that interrupt is not occurring????.....confused.....

- - - Updated - - -

any body there to help me out....
 

It might be better to let the interrupt routine just increment the mode_count. It is not a good idea to spend too much time in the interrupt routine.

Why do you clear the flag in your main loop?

while(1)
{
INTCON.INTF = 0; ?????
rgboff();
}

Something like this.

Code:
volatile unsigned char mode_count = 0;


void main()
{
unsigned char old_count = mode_count;

while(1)
  {
  if(old_count != mode_count)
    {
    old_count = mode_count;

    switch(mode_count)
      {
      case 1:
      NTCON.INTF = 0;
      flashrgb();
      break;
      
      case 2:
      INTCON.INTF = 0;
      strobe();
      break;

      etc.

      }

    while(Interrupt_pin == 0){ /* wait for button release */
      ;
      }

    if(mode_count > MAX_COUNT){
      mode_count = 0;
     }
    }
  }
}

/*--- Interrupt ---*/

void interrupt()
  {
  if(INTCON.INTF == 1)
    {
    mode_count++;
    INTCON.INTF = 0;
    }
  }
 

hi btbass....
thanks for the suggestion... but still its not working.....i think interrupt wont work wen executing the function like flashrgb(),strobe(),... which are out of the main loop!!!!
clueless....
need some help....
 

hello

i need port a pin2(RA2) acts like a switch

i don't know 16F676 but for 16F876 , Interrupt pins are located on PORTB, not PORTA
in particular RB0 pin !
 

hi all,
could any body have solution for the above problem.....
external interrupt its making me sleepless....
pls help me out.....
 

Have you tried using mplab sim debugger and stepping through the code?
You can set the interrupt flag in code to see if the interrupt routine is called.
 

i am using mikro c compiler.....
initially interrupt will occur and jumps to called fuction....
but wen i interrupt(pressed switch RA2) second time its not coming out of the loop....
below is my code.... pls take a look..... is that a correct way to call function wen using interrupt.... :roll:
Code:
#define red PORTC.F0
#define green PORTC.F1
#define blue PORTC.F2

#define mode PORTA.F2

void flashrgb();
void strobe();
void smooth();
void fadergb();
void rgboff();
unsigned char i,j,k,l,m,n;
unsigned int count,sec;
unsigned int signal_high;
unsigned int signal_low;
unsigned char readb;
unsigned char mode_count;

void interrupt()
{

  if(INTCON.INTF == 1)
  {
     mode_count++;
     INTCON.INTF = 0;
  }
}

void main()
{
 OPTION_REG = 0b00000000;
 WPUA = 0b00000100;
 INTCON.GIE = 1;
 INTCON.PEIE = 1;
 INTCON.INTE = 1;
 INTCON.INTF = 0;
 CMCON = 0x07;
 ANSEL = 0x00;
 TRISA = 0b111111;
 TRISC = 0b000000;
 PORTC = 0x00;
 mode_count = 0;
  while(1)
  {
      rgboff();
      //mode_count = mode_count+1;
      Delay_ms(100);

    switch(mode_count)
     {
        case 1:
        INTCON.INTF = 0;
        fadergb();
        break;

        case 2:
        INTCON.INTF = 0;
        flashrgb();
        break;

        case 3:
        INTCON.INTF = 0;
        fadergb();
        break;

        case 4:
        INTCON.INTF = 0;
        mode_count = 0;
        smooth();
        break;
     }
    
  }
}

void rgboff()
{
  
}

void fadergb()
{
   
}

void flashrgb()
{
  
}  

void strobe()
{
  
}

void smooth()
{
  
}
 

I have stepped through your code using mplab sim and it seems to work ok.
Maybe it is something to do with your button?
Try adding a wait for button release at the end of the while loop in main.

while(button == 0); /* wait for button release */
 

Try this

Code:
#define red PORTC.F0
#define green PORTC.F1
#define blue PORTC.F2

#define mode PORTA.F2

void flashrgb();
void strobe();
void smooth();
void fadergb();
void rgboff();
unsigned char i,j,k,l,m,n;
unsigned int count,sec;
unsigned int signal_high;
unsigned int signal_low;
unsigned char readb;
unsigned char mode_count;

void interrupt()
{

  if(INTCON.INTF == 1)
  {
     mode_count++;
     INTCON.INTF = 0;
     Delay_ms(20);
  }
}

void main()
{
 OPTION_REG = 0b00000000;
 WPUA = 0b00000100;
 INTCON.GIE = 1;
 INTCON.PEIE = 1;
 INTCON.INTE = 1;
 INTCON.INTF = 0;
 CMCON = 0x07;
 ANSEL = 0x00;
 TRISA = 0b111111;
 TRISC = 0b000000;
 PORTC = 0x00;
 mode_count = 0;
  while(1)
  {
      rgboff();
      //mode_count = mode_count+1;
      Delay_ms(100);

    switch(mode_count)
     {
        case 1:
        //INTCON.INTF = 0;
        fadergb();
        break;

        case 2:
        //INTCON.INTF = 0;
        flashrgb();
        break;

        case 3:
        //INTCON.INTF = 0;
        fadergb();
        break;

        case 4:
        //INTCON.INTF = 0;
        mode_count = 0;
        smooth();
        break;
     }
    
  }
}

void rgboff()
{
  
}

void fadergb()
{
   
}

void flashrgb()
{
  
}  

void strobe()
{
  
}

void smooth()
{
  
}

zip and post your proteus .dsn file.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top