Home > Back-end >  Infrared stc15f104w do accept application please find no problem
Infrared stc15f104w do accept application please find no problem

Time:10-10


# include "reg51. H"
# define uchar unsigned char
# define uint unsigned int
Sbit IRIN highlights=P3 ^ 2;//infrared receiver cable
Sbit out1=P3 ^ 0;
Sbit out2=P3 ^ 1;
//sbit out3=P3 ^ 2;
//sbit out4=P3 ^ 3;
////////////////////////////////////////////
//define array IRCOM, respectively after decoding the data
//IRCOM [0] low 8 address code
//IRCOM [1] the high 8-bit address code
//IRCOM [2] 8 bits of data code
//IRCOM [3] 8 bits of data code radix-minus-one complement
/////////////////////////////////////////////
Uchar m;
Uchar data IRCOM [4]=0;
Void IR_init (void);
Void delay014ms (unsigned char x);//* 0.14 MS x


Void delay014ms (unsigned char) x/x * 0.14 MS STC12C5410AD delay about 0.15 MS
{
Unsigned char I;
X -;
If (x> 0)
{
For (I=0; i<125; I++)//13
{; }

}
}
///////////////
//initialize
////////////
Void IR_init (void)
{
EA=1;
EX0=1;//allow always interrupt interrupted, enabling external interrupt INT0
IT0=1;//trigger mode for negative edge trigger pulse
IRIN highlights=1;//I/O port initialization
}
//////////
//decoding process
//////////////
Void IR_CODE (void) using interrupt 0 2//decoding in the external interrupt subroutine
{
Unsigned char j, k;
Unsigned int err, time=0, N=0;
EX0=0;
Delay014ms (15);
If (IRIN highlights==1)
{

EX0=1;
return;


}//confirm the IR signal in
while (! IRIN highlights//IR) is a high level, skip the 9 leading low level signal of ms,
{
Delay014ms (1);
N++;
If (N> 50)
{
EX0=1;
return;
}
}
N=0;
While (IRIN highlights//IR) is a low level, skip 4.5 ms leading high level signal,
{
Delay014ms (1);
N++;
If (N> 35)
{EX0=1;
return;
}

}
N=0;
For (j=0; j<4. J++) data collected four groups//
{
For (k=0; k<8; K++)//each set of data has eight
{err=10;
While ((IRIN highlights==0) & amp; & (err> 0))//IR into high level
{
Delay014ms (1);
Err,;
}
Err=40;
While ((IRIN highlights==1) & amp; & (err> 0))//IR high level time
{
Delay014ms (1);
time++;
Err,;
If (time>=30)
{
EX0=1;
return;
}//0.14 ms automatic counting too long leave,
}//high level finished count
IRCOM [j]=IRCOM [j] & gt;> 1;//data highest fill "0"
If (time>=8) {IRCOM [j]=IRCOM [j] | 0 x80; }//data highest fill "1"
Time=0;
}
}
If (IRCOM [2].=IRCOM ~ [3])//wait said decoding failure
//if (IRCOM [0]=0 x00ff & amp; & IRCOM [2].=IRCOM ~ [3])//wait said decoding failure

{
IRCOM [4]=0;
EX0=1;
return;
}
M=IRCOM [2].
The switch (m)
{
Case 0 x47:
The out1=1;
break;

Case 0 x44:
Out2=1;
break;

//case 0 x16:
//out3=1;
//break;
//case 0 x47:
//out4=1;
//break;
Default:
break;
}
EX0=1;
return;
}



//main program

Void main (void)
{
The out1=0;
Out2=0;
//out3=0;
//out4=0;
IR_init ();//initialize the external interrupt 0

TR1=1;//timer 1

While (1);


}
  • Related