/* 赤外線 受信機 Ver 3 BY M.Kikuchi PIC12F629 4MHz mikro-C V8.2 2009/3/20 Last:4/1 ; Format --------------------------------------------------- ; "0"X8bits,"1",C2,C1,C0,"0","1",D4,D3,D2,D1,D0,"1","0"x4bits ; C0toC2 is device code D0toD4 is switch data ;------------------------------------------------------------ CONFIG : $2007 _CPD_OFF _CP_OFF _BODEN_OFF _MCLRE_OFF _PWRTE_ON _WDT_OFF _INTRC_OSC_NOCLOCKOUT */ #define IFR_Sensor GPIO.F3 //L=active static unsigned short cnt,R_data; unsigned short IFR_RX() { R_BIT: for (cnt=0;cnt<3;cnt++){ //[0] 2bit Delay_us(290); if (IFR_Sensor == 0) goto R_BIT; } R_BIT2: if (IFR_Sensor == 1) goto R_BIT2; //[1] check & loop Delay_us(285); if (IFR_Sensor == 1) //again goto R_BIT; R_data=0; // for (cnt=0;cnt<3;cnt++){ //3bits Delay_us(580); if (IFR_Sensor == 0) R_data.F0=1; else R_data.F0=0; R_data<<1; } // Delay_us(585); if (IFR_Sensor == 0) goto R_BIT; //[0] Delay_us(585); if (IFR_Sensor == 1) goto R_BIT; //[1] // for (cnt=0;cnt<5;cnt++){ //5bits Delay_us(580); if (IFR_Sensor == 0) R_data.F0=1; else R_data.F0=0; if (cnt != 4) //keep of Last bit R_data=R_data<<1; } // Delay_us(585); if (IFR_Sensor == 1) goto R_BIT; //[1] Delay_us(585); if (IFR_Sensor == 0) goto R_BIT; //[0] return(R_data); } void main() { unsigned short Rdata1,Rdata2; // CMCON =0b00000111; //un use Compalater TRISIO=0b00001000; //0=output 1=input asm{ //Tuning call 0x3ff; movwf OSCCAL; } GPIO=0; //check LED ON-OFF for (cnt=0;cnt<4;cnt++){ GPIO.F0=~GPIO.F0; Delay_ms(100); } while(1) { START: do{ Rdata1=IFR_RX(); //1st Rdata2=IFR_RX(); //2nd } while (Rdata1 != Rdata2); if ((Rdata1 && 0xE0)!= 0x80) //device check // switch (Rdata1 & 7) { case 1: GPIO.F0=~GPIO.F0; break; case 2: GPIO.F1=~GPIO.F1; break; case 3: GPIO.F2=~GPIO.F2; break; case 4: GPIO.F4=~GPIO.F4; break; case 5: GPIO.F5=~GPIO.F5; break; default: GPIO=0; //clear } } }