After my testing, LED is not on, that is, interrupt is not happed. I don't know where the error of my code is.
Thanks
Ionic
Here is my code:
Code: Select all
int main( void )
{
ADPCFG = 0xfff0;
TRISBbits.TRISB7 = 0;
LATBbits.LATB7 = 0; // for testing interrupt
Init_CMP1();
while(1)
{
Sleep()
}
}
void Init_CMP1(void)
{
IPC7bits.AC1IP = 7;
IEC1bits.AC1IE = 1;
CMPCON1bits.INSEL = 0; // CMP1A:RB0
CMPCON1bits.EXTREF = 0; //Interal Ref
CMPCON1bits.RANGE = 1; //AVDD/2
CMPCON1bits.CMPPOL= 0; //non inverted
CMPDAC1 = 0x01FF; //Ref=AVDD/4=1.25V;
CMPCON1bits.CMPON = 1; /* CMP1 enabled */
}
void _ISR _CMP1Interrupt(void)
{
LATBbits.LATB7 = 1; // if interrupt is happened, RB7 is set to 1
IEC1bits.AC1IE = 0; // turn off interrupt enable
IFS1bits.AC1IF = 0;
}
But the problem still exits.