能
#include<reg52.h>
typedef unsigned char u8;
typedef unsigned int u16;
u8 code FFW[8]={0x01,0x03,0x02,0x06,0x04,0x0c,0x08,0x09};
u8 code REV[8]={0xf9,0xf8,0xfc,0xf4,0xf6,0xf2,0xf3,0xf1};
u16 code smgduan[17]={0,1,2,3,4};
u8 IrValue[6];
u8 Time;
u8 read;
u8 DisplayData[8];
sbit IRIN=P3^2;
sbit LSA=P2^2;
sbit LSB=P2^3;
sbit LSC=P2^4;
void delay(u16 i)
{
while(i--);
}
void delayB(u16 i)
{ u16 n;
while(i--)
{ for(n=0;n<125;n++) {}
}
}
void DigDisplay()
{
DisplayData[0] = smgduan[IrValue[2]/16];
DisplayData[1] = smgduan[IrValue[2]%16];
DisplayData[2] = smgduan[16];
}
void irread()
{
IT0=1;
EX0=1;
EA=1;
IRIN=1;
}
void motor_ffw()
{
u8 i;
for (i=0; i<8; i++)
{
P1 = FFW;
delayB(5);
}
}
void motor_rev()
{
u8 i;
for (i=0; i<8; i++)
{
P1 = REV;
delayB(5);
}
}
void main()
{ irread();
while(1)
{
DigDisplay();
if((DisplayData[0]==4)&&(DisplayData[1]==3))
motor_ffw();
if((DisplayData[0]==4)&&(DisplayData[1]==0))
motor_rev();
if((DisplayData[0]==4)&&(DisplayData[1]==4))
P1=0x0f;
}
}
void ReadIr() interrupt 0
{
u8 j,k;
u16 err;
Time=0;
delay(700);
if(IRIN==0)
{
err=1000;
while((IRIN==0)&&(err>0))
{
delay(1);
err--;
}
if(IRIN==1)
{
err=500;
while((IRIN==1)&&(err>0))
{
delay(1);
err--;
}
for(k=0;k<4;k++)
{
for(j=0;j<8;j++) /?????
{
err=60;
while((IRIN==0)&&(err>0))
{
delay(1);
err--;
}
err=500;
while((IRIN==1)&&(err>0))
{
delay(10); //0.1ms
Time++;
err--;
if(Time>30)
{
return;
}
}
IrValue[k]>>=1;
if(Time>=8)
{
IrValue[k]|=0x80;
}
Time=0;
}
}
}
if(IrValue[2]!=~IrValue[3])
{
return;
}
} }
|