|
本帖最后由 lclbf 于 2019-10-19 10:43 編輯
遙控部分程序如下:#include<reg51.h>
sbit IR_INPUT = P3^3;
bit irflag = 0;
unsigned char ircode[4];
void InitInfrared()
{
IR_INPUT = 1;
TMOD &= 0X0F;
TMOD |= 0X10;
TR1 = 0;
ET1 = 0;
IT1 = 1;
EX1 = 1;
}
unsigned int GetHighTime()
{
TH1 = 0;
TL1 = 0;
TR1 = 1;
while (IR_INPUT)
{
if (TH1 >= 0X40)
{
break;
}
}
TR1 = 0;
return (TH1*256 + TL1);
}
unsigned int GetLowTime()
{
TH1 = 0;
TL1 = 0;
TR1 = 1;
while (!IR_INPUT)
{
if (TH1 >= 0X40)
{
break;
}
}
TR1 = 0;
return (TH1*256 + TL1);
}
void EXINT1_ISR() interrupt 2
{
unsigned char i,j;
unsigned char byt;
unsigned int time;
time = GetLowTime();
if ((time<7833)||(time>8755))
{
IE1 = 0;
return;
}
time = GetHighTime();
if ((time<3686)||(time>4608))
{
IE1 = 0;
return;
}
for (i=0;i<4;i++)
{
for (j=0;j<8;j++)
{
time = GetLowTime();
if ((time<313)||(time>718))
{
IE1 = 0;
return;
}
time = GetHighTime();
if ((time>313)&&(time<718))
{
byt >>= 1;
}
else if ((time>1345)&&(time<1751))
{
byt >>= 1;
byt |= 0x80;
}
else
{
IE1 = 0;
return;
}
}
ircode = byt;
}
irflag = 1;
IE1 = 0;
}
|
|