/*错误已找出,是因为case后的遥控器解码值错了。错在数据码和反码前后反了。!!即以前的解码程序中的数据码和反码前后反了!!*/
#include
#define c(x) (x*110592/120000)
sbit Ir_Pin=P2^2;
unsigned char Ir_Buf[4];
unsigned char code fangxiang[]={0xA0,0X14,0XB4,0X6C,0X60,0X0C,0X00};
unsigned int Ir_Get_Low()
{
TL1=0;
TH1=0;
TR1=1;
while(!Ir_Pin && (TH1&0x80)==0);
TR1=0;
return TH1*256+TL1;
}
//=============================================================
unsigned int Ir_Get_High()
{
TL1=0;
TH1=0;
TR1=1;
while(Ir_Pin && (TH1&0x80)==0);
TR1=0;
return TH1*256+TL1;
}
//==============================================================
main()
{
unsigned int temp;
unsigned char i,j;
TMOD=0x11;
EA=1;
do{
restart:
while(Ir_Pin);
temp=Ir_Get_Low();
if(temp
temp=Ir_Get_High();
if(temp
for(i=0;i<4;i++) //4???
for(j=0;j<8;j++) //????8?
{
temp=Ir_Get_Low();
if(temp
temp=Ir_Get_High();
if(temp
Ir_Buf[i]>>=1;
if(temp>c(1120)) Ir_Buf[i]|=0x80;
}
switch(Ir_Buf[3])
{
case 0x53:P1=fangxiang[0];break;
case 0x43:P1=fangxiang[1];break;
case 0x4f:P1=fangxiang[2];break;
case 0x5f:P1=fangxiang[3];break;
case 0x63:P1=fangxiang[4];break;
case 0x3f:P1=fangxiang[5];break;
case 0x3b:P1=fangxiang[6];break;
default:break;
}
}
while(1);
}
已发请查收
看我这个刚做的,用L298,很菜的~~
http://hi.baidu.com/%B4%F3%B2%DD%D4%AD%BB%C6%BB%A8%B2%CB/blog/item/b50558f206ae2f4a352acc2e.html