mplabx wont debug

Status
Not open for further replies.
You have to physically read the port so the IOC interrupt can latch.
C:
void interrupt interupt(void)
{
unsigned char dummy;
setRELAY(1);
LED(1);
__delay_ms(300);
setRELAY(0);
LED(0);
Interrupt_occured = 1; 
dummy = PORTA;
RAIF= 0; // clear flag
GIE = 1; // enable global interrupts
 
Not sure which chip you're using but you may need to set PIE bit as well.

Mike.
 
figured better to revive this thread since it s another interrupt problem and i have feeling it will be solved in blink of eye, ie Error Code# ID10T!
16f688 still, but now using int0/RA2 interrupt -- triggered by IR receiver

Problem is that when sending ir pulse(RC5), the int0 still triggers, even though i have disabled it and reset flags after, i have created delays and checked hardware for noise:
... the second chunk of code is just to show how functions are called and things are setup
... the first chunk of code is more of the problem:


Code:
unsigned int getIR(void)
{  
    if (RA2 == 0) /// IR DETected on INT0
{      
        PerimeterDelay = 1200;            // reset IR flag
        if (IRmode > 0){rawLED(IRmode);}  // display on RGB output without timer0 since we are already on interrupt routine
    delayMS(200);                                 // stall a little bit for now, function will soon get alot bigger
    }          
    return 1;                                          // default respnose for now
}


void PulseIR(unsigned char count)
{      
    unsigned char  dummy;
    INTCONbits.INTE = 0;      // THIS LINE SHOULD SHUT INT0 OFF but it dont!
    delayMS(count);           // DELAY SO INT0 can shut off, finish up, and not catch any echos



    PORTC |= 0b00100000;       // turn on IR pulseRC5
//hardware is tied to 40khz multivibrator
// scope show IR to be turning on and off  properly

// removing this line device works properly where leD turns green until
// (PerimeterDelay=0 then turns magenta, turns green again when
// triggered  by external IR pulses (tv remote)


// LEAVING this line in causes the RC5 IR to trigger INT0, causing
// PerimeterDelay to reset and LED never turns magenta
// even though previous line clearly says INTE=0;




    delayMS(count);                 // leave IR running for a bit
    PORTC &= 0b11011111;      // IR LED is shutting off properly
    delayMS(count);   // wait for IR echos and maybe circuit noise to disipate
    dummy = PORTA;            // just in case
    INTCONbits.INTF = 0;      /// clear flag
    INTCONbits.INTE = 1;    // reenable    
}


void ModePerimeter(void)
{      
    if (PerimeterDelay == 0)
    {
        setColorB(8-color);       // MAGENTA on timer0 routine
    }
    else if(PerimeterDelay == PerimeterAlert/2)
    {    
        PulseIR(200);               // problematic fucntion
        PerimeterDelay--;      
    }
    else    
    {
        setColorB(color);          //GREEN on timer0 routine
        PerimeterDelay--;
    }  
}




Code:
void interrupt  INTERRUPT()
{    
    unsigned char  dummy;
    if(INTCONbits.INTF == 1)   { Remote = getIR(); dummy = PORTA;  }
    else if (INTCONbits.T0IF == 1)
    {      
       runLED(Red,Green,Blue);    // runs RGB led with TMR0
       TMR0 = 200;                         
    }      
       INTCONbits.INTF = 0;
       INTCONbits.T0IF = 0;
}

void setup(void)
{  
    TRISA = 0b11111111;
    PORTA = 0b00000000;
    TRISC = 0b11000011;
    PORTC = 0b00011100;
    ANSEL = 0b00011000;
      
    CMCON0= 0b00000000;
  
  
    OSCCONbits.SCS = 1;
    OSCCONbits.IRCF0 = 1;
    OSCCONbits.IRCF1 = 1;
    OSCCONbits.IRCF2 = 1;
    
  
    ADCON1bits.ADCS  = 6;   //Selecting the clk division factor = FOSC/2
    ADCON0bits.ADFM = 1;    //Result right justified
    ADCON0bits.VCFG = 0;    //Result right justified  
  
  
    OPTION_REGbits.INTEDG  = 0; //cause interrupt at falling edge
    OPTION_REGbits.T0CS = 0;  
    TMR0 = 0; 
  
    INTCONbits.INTF = 0; //reset interrupt flag 
    INTCONbits.T0IF = 0;
    
    
    delayMS(3000);
  

    INTCONbits.INTE = 1; //enable Interrupt 0 (RA2 as interrupt)
  
    setColorB(color = 2);   // green
    setColorB(0);               // clear it for now
    IRmode = 3;                // Blue

    ei();    // This is like fliping the master switch to enable interrupt
}
int main(int argc, char** argv)
{  
    setup();
    while (1)      
    {      
ModePerimeter();
  
    }    
    }
 
Last edited:
The INTF bit will still get set and the timer interrupt will still occur. Change if(INTCONbits.INTF == 1) to if(INTF == 1 && INTE==1) and all should be well.

Mike.
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…