I can''t receive interrupt signal on my mcu by infrared sensor IR attached on RA2(int).
Probabily or i forgot to set some part of INTCON register, or part of interrupt code is wrong and not use RA2 as interrupt !!!
On the datasheet there's wrote that RA2 is default Interrupt pin, so probabily remappable Interrupt is not required !!
Below interrupt code and in attachement there's full code and a little part of mcu datasheet.
Thank you for your Help.
PS: actually I'm using an IR Transmitter remote control In program if this signal is received send me a simply message on UART. (next step will be build a real code for receive and trasmit remote IR data for example an hi-fi )
Code: Select all
void interrupt()
{
if (TMR0IF_bit){
TMR0IF_bit=0;
TMR0H = 0b1011; // =hex 0b
TMR0L = 0b11011100; // =dc
LATC7_bit= ~LATC7_bit; // led blinking
}
// INTERRUPT ON RA2
if (INTF_bit) // && INTE_bit
{
IR_flag = 1;
INTF_bit = 0;
}
}
Code: Select all
void main() {
// PORT SET
TRISA=0b00000000;
TRISB=0b00000000;
TRISC=0b00000000; //0=output, 1=input
TRISA.B2 = 1; // Set RA2 as input for Infrared Decoder interrupt
WPUA = 0b00000100; // set pull-up for RA2 (IR interrupt)
PORTA=0; PORTB=0; PORTC=0;
// Disable comparators
C1ON_bit = 0;
C2ON_bit = 0;
CM1CON0=0;
CM2CON0=0;
ANSELA = 0x00; // configure all PORTA pins as digital
ANSELB = 0x00; // configure all PORTB pins as digital
ANSELC = 0b00001111;
UART1_Remappable_Init(9600);
RC5PPS = 0x14;// 00010100 PIN Rxy OUTPUT SOURCE SELECTION REGISTER source is TX/CK(1) // UART Tx output RC5
RXPPS = 0x14; // 00010100 PERIPHERAL xxx INPUT SELECTION input is RC4 RX // UART RX input RC4
Delay_ms(100); // UART settle time
arm_interrupt_timer0();
// REMAPPABLE INT PIN ON RA2 (on datasheet pag.164)
INTPPS = 0x02; //INTPPS = 0b00000010; //RA2 > INT 0x0002
Delay_ms(100);
INTEDG_bit = 0; //Interrupt on falling edge of INT pin (fronte di discesa)
PEIE_bit = 1;
//INTE_bit = 1;
GIE_bit = 1;
IR_flag = 0;
UART1_Write_CText (" Test : \r\n");
while(1){
if(IR_flag) {IR_flag=0; UART1_Write_CText("Interrupt on RA2 OK!!\r\n");
}
} // WND WHILE(1)
} // END MAIN