Beispiel #1
0
/*
 * ir_timeout : this function is called when timer1 overflows.
 */
void
ir_timeout(void)
{
#if IR_RAW_SUPPORT == 1
	ir_raw[ir_ptr] = 0xff;
#endif
	ir_flags.timeout = 1;

	/* stop timer 1 */
	T1CONbits.TMR1ON = 0;

	/* decode what we got ! */
	ir_decode();

	if (ir_flags.decoded) {
		/* wait for the caller to re-enable reception */
		ir_disable();
	} else {
		Nop();
	}

	/* reset capture edge */
	OpenCapture1(CAPTURE_INT_ON & C1_EVERY_FALL_EDGE);
	ir_flags.edge = 0;

	ir_reset();
}
/*
 * ir_interrupt : this function must be called when the capture interrupt
 *                occurs.
 */
void
ir_interrupt(void)
{
	/* reload timer 1 */
	TMR1H = T1_RELOAD_H;
	TMR1L = T1_RELOAD_L;

	/* change edge */
	if (ir_flags.edge) {
		//OpenCapture1(CAPTURE_INT_ON & C1_EVERY_FALL_EDGE);
                CCP1IE = 1;
                CCP1M0 = 0;
		ir_flags.edge = 0;
	} else {
		//OpenCapture1(CAPTURE_INT_ON & C1_EVERY_RISE_EDGE);
                CCP1IE = 1;
                CCP1M0 = 1;
		ir_flags.edge = 1;
	}

	if (ir_flags.first) {
		/* This is the first edge. Start timer1 */
		//T1CONbits.TMR1ON = 1;
		TMR1ON = 1;
#if IR_RAW_SUPPORT == 1
		ir_ptr = 0;
#endif
		ir_decode();

		ir_flags.first = 0;
		return;
	}

#if IR_RAW_SUPPORT == 1
	ir_raw[ir_ptr] = CCPR1H;	// ir_raw in multiple of 64us
	ir_ptr++;
	if (ir_ptr == IR_RAW_SIZE - 1) {
		ir_ptr = 0;
		//ir_timeout();
	}
#endif

	ir_decode();
}
Beispiel #3
0
interrupt(PORT1_VECTOR) P1_ISR(void)
{
    if ((P1IFG & IR_BIT) == IR_BIT)
        ir_decode();

    if ((P1IFG & RXD) == RXD)
        uart_p1_isr();

    P1IFG = 0x00;   // clear interrupt flags
}
Beispiel #4
0
void main(void) {
    unsigned short pwkey = 0;
    TRISAbits.RA0 = 0;

    ir_enableIRIn();
    ir_blink13(0);
    while(1)
    {
        if (ir_decode(&dec_results)) {
            if (dec_results.decode_type == NEC)
            {
                
                switch(dec_results.value)
                {
                    case TERRATEC_1_KEY:
                        pwkey = pwkey << 4;
                        pwkey |= 1;
                        break;
                    case TERRATEC_2_KEY:
                        pwkey = pwkey << 4;
                        pwkey |= 2;
                        break;
                    case TERRATEC_3_KEY:
                        pwkey = pwkey << 4;
                        pwkey |= 3;
                        break;
                    case TERRATEC_4_KEY:
                        pwkey = pwkey << 4;
                        pwkey |= 4;
                        break;
                    case TERRATEC_5_KEY:
                        pwkey = pwkey << 4;
                        pwkey |= 5;
                        break;
                    case TERRATEC_6_KEY:
                        pwkey = pwkey << 4;
                        pwkey |= 6;
                        break;
                    case TERRATEC_7_KEY:
                        pwkey = pwkey << 4;
                        pwkey |= 7;
                        break;
                    case TERRATEC_8_KEY:
                        pwkey = pwkey << 4;
                        pwkey |= 8;
                        break;
                    case TERRATEC_9_KEY:
                        pwkey = pwkey << 4;
                        pwkey |= 9;
                        break;
                    case TERRATEC_0_KEY:
                        pwkey = pwkey << 4;
                        pwkey |= 0;
                        break;
                    case REPEAT:
                        break;
                    case TERRATEC_OK_KEY:
                        ir_sendNEC(APPLE_PLAY_KEY,32);
                        break;
                    case TERRATEC_UP_KEY:
                        ir_sendNEC(APPLE_UP_KEY,32);
                        break;
                    case TERRATEC_DOWN_KEY:
                        ir_sendNEC(APPLE_DOWN_KEY,32);
                        break;
                    case TERRATEC_LEFT_KEY:
                        ir_sendNEC(APPLE_LEFT_KEY,32);
                        break;
                    case TERRATEC_RIGHT_KEY:
                        ir_sendNEC(APPLE_RIGHT_KEY,32);
                        break;
                    case TERRATEC_INFO_KEY:
                        ir_sendNEC(APPLE_MENU_KEY,32);
                        break;
                    default:
                        LATAbits.LATA0 = 0;
                        pwkey = pwkey << 4;
                        break;
                }
                if (pwkey == 0x7412)
                {

                        LATAbits.LATA0 = 1;
                }
                else
                {
                        LATAbits.LATA0 = 0;
                }
            }
            //do something here
            ir_resume(); // Receive the next value
        }
    }

}