/* * Program: IRRecv-DetectPF.nxc * By CH, Chen; 10-13-2009 * Using Hitechnic IRRecv to detect PF RC IR signals and display details */ #define IRRECV_PORT S1 #define I2C_DEVICE 0x02 #define CONTROL_FIELD 0x42 byte I2C_buf[]; /* ******************************************************** * Display receiving data from registers 0x42 till 0x49 *1234567890123456 * A B *Ch1 *Ch2 *Ch3 *Ch4 * ******************************************************** */ void DisplayMotorCtrl() { char a_val, b_val; ClearScreen(); TextOut(0, LCD_LINE1, "Detect by IRRecv" ); TextOut(0, LCD_LINE3, " A B" ); //A,B - 24,54 TextOut(0, LCD_LINE4, "Ch1 " ); TextOut(0, LCD_LINE5, "Ch2 " ); TextOut(0, LCD_LINE6, "Ch3 " ); TextOut(0, LCD_LINE7, "Ch4 " ); for (int xii=0; xii<4; xii++) { a_val = I2C_buf[xii*2]; b_val = I2C_buf[xii*2+1]; NumOut(24, LCD_LINE4-8*xii, a_val); NumOut(54, LCD_LINE4-8*xii, b_val); } } /* ******************************************************** * Detect LPF RC IR singals * ******************************************************** */ void DetectPFRC() { byte xstatus, nbytes; byte I2C_get_buf[]; ArrayBuild(I2C_get_buf, I2C_DEVICE, CONTROL_FIELD); ArrayInit(I2C_buf, 0, 8); while(LowspeedCheckStatus(IRRECV_PORT) == STAT_COMM_PENDING); LowspeedWrite(IRRECV_PORT, 8, I2C_get_buf); while(LowspeedStatus(IRRECV_PORT, nbytes) == STAT_COMM_PENDING); xstatus = LowspeedRead(IRRECV_PORT, nbytes, I2C_buf); Wait(50); DisplayMotorCtrl(); } /* ******************************************************** * Initialize I2C sensor * ******************************************************** */ void I2C_Init() { SetInput(IRRECV_PORT, InvalidData, true); SetSensorLowspeed(IRRECV_PORT); while (SensorInvalid(IRRECV_PORT)); } /* ******************************************************** * main routine * ******************************************************** */ task main() { I2C_Init(); ClearScreen(); TextOut(0, LCD_LINE3, "Here is IRRecv " ); TextOut(0, LCD_LINE8, "Enter to detect " ); until (ButtonPressed(BTNCENTER, TRUE)); while(TRUE) DetectPFRC(); }