TL1838红外通信模块的发射接收问题(求帮忙,可转账)
时间:10-02
整理:3721RD
点击:
如题,我想知道为什么遥控器按下第一个键的地址就是0X16,我应该怎么知道为什么0x16是第一个键。源程序如下
#include<reg51.h>
#define uchar unsigned char
#define uint unsigned int
#define zhujia1 0x16
#define zhujia2 0x19
#define zhujia3 0x0d
#define zhujian1 0x0c
#define zhujian2 0x18
#define zhujian3 0x5e
#define kejia1 0x08
#define kejia2 0x1c
#define kejia3 0x5a
#define kejian1 0x42
#define kejian2 0x52
#define kejian3 0x4a
#define kaishi 0x45
#define zanting 0x46
#define qingling 0x47
#define fuwei 0x09
#define zf1 0x07
#define kf1 0x15
#define qingping 0x09
sbit rs= P3^1;
sbit en= P3^0;
sbit beep=P3^7;
sbit aj1=P1^0;
sbit aj2=P1^1;
sbit aj3=P1^2;
sbit bj1=P1^3;
sbit bj2=P1^4;
sbit bj3=P1^5;
sbit ajan=P3^2;
sbit bjan=P3^5;
sbit ks=P1^7;
sbit zt=P3^4;
sbit ql=P1^6;
sbit qf=P3^3;
bit flang;
uchar irdate[33];//红外解码时间暂存
uchar irbyte[4]; //红外处理数据暂存
uchar key_num;
uchar zhufan,kefan;
uchar irtime,irflag,bitnum,irdateok;
uchar num, zhudui,kedui,jie; //定义主队客队分数变量
char fen,miao,msc24; //定义时间变量
uchar code jiadui[] = {"甲队"};
uchar code yidui[] = {"乙队"};
uchar code zantingzhong[] = {"暂停中"};
uchar code bisaizhong[] = {"比赛中"};
uchar code diyijie[] = {"第一节"};
uchar code dierjie[] = {"第二节"};
uchar code disanjie[] = {"第三节"};
uchar code disijie[] = {"第四节"};
uchar code putongmoshi[] = {"普通模式"};
uchar code table[] = {"0123456789ABCDEF"};
void delay(int z) //延时子程序
{
uint x;
uchar y;
for(x=z;x>0;x--)
for(y=100;y>0;y--);
}
void write_com(uchar com)//液晶写地址函数
{
en=0;delay(1);
rs=0;delay(1);
P2=com;delay(1);
en=1;delay(1);
en=0;delay(1);
}
void write_data(uchar date) //液晶写数据函数
{
en=0;delay(1);
rs=1;delay(1);
P2=date;delay(1);
en=1;delay(1);
en=0;delay(1);
}
void lcd_init()//液晶显示初始化函数
{
uchar i;
delay(100);
write_com(0x30);
delay(1);
write_com(0x30);
delay(1);
write_com(0x0c); //开显示开关,关光标
delay(1);
write_com(0x01); //清除显示
delay(15);
write_com(0x06); //进入模式设置
delay(1);
write_com(0x88);
for(i=0;i<6;i++)
write_data(diyijie[i]);
}
void xitonginit() //系统初始化
{
beep=1;
zhudui=0;
kedui=0;
jie=1;
msc24=24;
fen=10;
miao=0;
EA=1;
ET1=1;
TMOD=0x12;
TH0=0;
TL0=0;
EA=1;
EX0=1;
ET0=1;
TR0=1;
IT0=1;
ET1=1;
}
void xianshi()
{
uchar i;
if(jie<3)
{
write_com(0x81);
for(i=0;i<4;i++)
write_data(jiadui[i]);
write_com(0x85);
for(i=0;i<4;i++)
write_data(yidui[i]);
write_com(0x92);
write_data(table[zhudui/10]);
write_data(table[zhudui%10]);
write_com(0x94);
write_data(table[kedui/10]);
write_data(table[kedui%10]);
write_com(0x90);
write_data(table[zhufan/16]);
write_data(table[zhufan%16]);
write_com(0x96);
write_data(table[kefan/16]);
write_data(table[kefan%16]);
}
else
{
write_com(0x85);
for(i=0;i<4;i++)
write_data(jiadui[i]);
write_com(0x81);
for(i=0;i<4;i++)
write_data(yidui[i]);
write_com(0x94);
write_data(table[zhudui/10]);
write_data(table[zhudui%10]);
write_com(0x92);
write_data(table[kedui/10]);
write_data(table[kedui%10]);
write_com(0x96);
write_data(table[zhufan/16]);
write_data(table[zhufan%16]);
write_com(0x90);
write_data(table[kefan/16]);
write_data(table[kefan%16]);
}
write_com(0x8c);
write_data(table[fen/10]);
write_data(table[fen%10]);
write_data(':');
write_data(table[miao/10]);
write_data(table[miao%10]);
write_data(' ');
write_data(table[msc24/10]);
write_data(table[msc24%10]);
if(TR0==1)
{
write_com(0x98);
for(i=0;i<6;i++)
write_data(bisaizhong[i]);
}
else
{
write_com(0x98);
for(i=0;i<6;i++)
write_data(zantingzhong[i]);
}
write_com(0x9c);
for(i=0;i<8;i++)
write_data(putongmoshi[i]);
if(flang==1)
{
TR0=0;
flang=0;
if(jie<4)
{
beep=0;
delay(7000);
beep=1;
}
else
{
beep=0;
delay(15000);
beep=1;
}
fen=10;
miao=0;
msc24=24;
jie++;
if(jie>4)
{
jie=4;
}
switch(jie)
{
case 1: //第一节
write_com(0x88);
for(i=0;i<6;i++)
write_data(diyijie[i]);
break;
case 2:
write_com(0x88);
for(i=0;i<6;i++)
write_data(dierjie[i]);
break;
case 3: //第三节
write_com(0x88);
for(i=0;i<6;i++)
write_data(disanjie[i]);
break;
break;
case 4: //第四节
write_com(0x88);
for(i=0;i<6;i++)
write_data(disanjie[i]);
break;
}
if(jie>4) //比赛时间到
{
beep=0;
delay(35000);
beep=1;
}
else
{
beep=0;
delay(35000);
beep=1;
}
}
}
void deal_with()//判断时间,转换处理数据
{
uchar i,j,k,temp;
k=1;
for(j=0;j<4;j++) //、、一共32位数据
{
for(i=0;i<8;i++)
{
temp=temp>>1;
if(irdate[k]>7)
{
temp=temp|0x80;
}
k++;
}
irbyte[j]=temp;
}
}
void qing_ling()//暂存数据清楚
{
uchar i;
for(i=0;i<33;i++)
irdate[i]=0;
for(i=0;i<4;i++)
irbyte[i]=0;
}
void anjian() //按键检测
{
if(irdateok==1)//解码成功
{
irdateok=0;
deal_with();
}
//////////////////////////////////////////////////数据判断,处理
key_num=irbyte[2];
if(irbyte[2]==zhujia1){ zhudui++; TR1=0; msc24=24; } // 主队加一分
if(irbyte[2]==zhujia2){ zhudui+=2; TR1=0; msc24=24; } // 主队加两分
if(irbyte[2]==zhujia3){ zhudui+=3; TR1=0; msc24=24; } // 主队加三分
if(irbyte[2]==zhujian1){ if(zhudui>0)zhudui--; TR1=0; msc24=24; }
if(irbyte[2]==zhujian2){ if(zhudui>1)zhudui-=2; TR1=0; msc24=24; }
if(irbyte[2]==zhujian3){ if(zhudui>2)zhudui-=3; TR1=0; msc24=24; }
if(irbyte[2]==kejia1){ kedui++; TR1=0; msc24=24; } // 客队加一分
if(irbyte[2]==kejia2){ kedui+=2; TR1=0; msc24=24; } // 客队加两分
if(irbyte[2]==kejia3){ kedui+=3; TR1=0; msc24=24; } //客队加三分
if(irbyte[2]==kejian1){ if(kedui>0)kedui--; TR1=0; msc24=24; }
if(irbyte[2]==kejian2){ if(kedui>1)kedui-=2; TR1=0; msc24=24; }
if(irbyte[2]==kejian3){ if(kedui>2)kedui-=3; TR1=0; msc24=24; }
if(irbyte[2]==zf1){ zhufan++; TR1=0; msc24=24; }
if(irbyte[2]==kf1){ kefan++; TR1=0; msc24=24; }
if(irbyte[2]==zanting){TR1=0;}
if(irbyte[2]==kaishi){TR1=1;}
if(irbyte[2]==qingling){msc24=24;}
if(irbyte[2]==qingping){zhudui=0;kedui=0;zhufan=0;kefan=0;TR1=0; msc24=24; beep=1; fen=10;miao=0;}
qing_ling();
}
void main()
{
xitonginit();
lcd_init();
while(1)
{
xianshi();
anjian();
}
}
void temer1() interrupt 3 //定时器0 中断函数
{
TH1=15;
TL1=0;
num++;
if(num==16)
{
num=0;
miao--;
if(miao<0)
{
fen--;
miao=59;
if(fen<0) flang=1;
}
//if(ql)
msc24--;
if(msc24==0) //24秒后暂停
{
TR1=0;
msc24=24;
beep=0;
delay(3500);
beep=1;
}
}
}
void T0_time() interrupt 1
{
irtime++;
}
void int0() interrupt 0 // 以下解码程序是固定
{
if(irflag==1)
{
if(irtime>32)
{
bitnum=0;
}
irdate[bitnum]=irtime;
irtime=0;
bitnum++;
if(bitnum==33)
{
bitnum=0;
irdateok=1;
}
}
else
{
irflag=1;
irtime=0;
}
}
#include<reg51.h>
#define uchar unsigned char
#define uint unsigned int
#define zhujia1 0x16
#define zhujia2 0x19
#define zhujia3 0x0d
#define zhujian1 0x0c
#define zhujian2 0x18
#define zhujian3 0x5e
#define kejia1 0x08
#define kejia2 0x1c
#define kejia3 0x5a
#define kejian1 0x42
#define kejian2 0x52
#define kejian3 0x4a
#define kaishi 0x45
#define zanting 0x46
#define qingling 0x47
#define fuwei 0x09
#define zf1 0x07
#define kf1 0x15
#define qingping 0x09
sbit rs= P3^1;
sbit en= P3^0;
sbit beep=P3^7;
sbit aj1=P1^0;
sbit aj2=P1^1;
sbit aj3=P1^2;
sbit bj1=P1^3;
sbit bj2=P1^4;
sbit bj3=P1^5;
sbit ajan=P3^2;
sbit bjan=P3^5;
sbit ks=P1^7;
sbit zt=P3^4;
sbit ql=P1^6;
sbit qf=P3^3;
bit flang;
uchar irdate[33];//红外解码时间暂存
uchar irbyte[4]; //红外处理数据暂存
uchar key_num;
uchar zhufan,kefan;
uchar irtime,irflag,bitnum,irdateok;
uchar num, zhudui,kedui,jie; //定义主队客队分数变量
char fen,miao,msc24; //定义时间变量
uchar code jiadui[] = {"甲队"};
uchar code yidui[] = {"乙队"};
uchar code zantingzhong[] = {"暂停中"};
uchar code bisaizhong[] = {"比赛中"};
uchar code diyijie[] = {"第一节"};
uchar code dierjie[] = {"第二节"};
uchar code disanjie[] = {"第三节"};
uchar code disijie[] = {"第四节"};
uchar code putongmoshi[] = {"普通模式"};
uchar code table[] = {"0123456789ABCDEF"};
void delay(int z) //延时子程序
{
uint x;
uchar y;
for(x=z;x>0;x--)
for(y=100;y>0;y--);
}
void write_com(uchar com)//液晶写地址函数
{
en=0;delay(1);
rs=0;delay(1);
P2=com;delay(1);
en=1;delay(1);
en=0;delay(1);
}
void write_data(uchar date) //液晶写数据函数
{
en=0;delay(1);
rs=1;delay(1);
P2=date;delay(1);
en=1;delay(1);
en=0;delay(1);
}
void lcd_init()//液晶显示初始化函数
{
uchar i;
delay(100);
write_com(0x30);
delay(1);
write_com(0x30);
delay(1);
write_com(0x0c); //开显示开关,关光标
delay(1);
write_com(0x01); //清除显示
delay(15);
write_com(0x06); //进入模式设置
delay(1);
write_com(0x88);
for(i=0;i<6;i++)
write_data(diyijie[i]);
}
void xitonginit() //系统初始化
{
beep=1;
zhudui=0;
kedui=0;
jie=1;
msc24=24;
fen=10;
miao=0;
EA=1;
ET1=1;
TMOD=0x12;
TH0=0;
TL0=0;
EA=1;
EX0=1;
ET0=1;
TR0=1;
IT0=1;
ET1=1;
}
void xianshi()
{
uchar i;
if(jie<3)
{
write_com(0x81);
for(i=0;i<4;i++)
write_data(jiadui[i]);
write_com(0x85);
for(i=0;i<4;i++)
write_data(yidui[i]);
write_com(0x92);
write_data(table[zhudui/10]);
write_data(table[zhudui%10]);
write_com(0x94);
write_data(table[kedui/10]);
write_data(table[kedui%10]);
write_com(0x90);
write_data(table[zhufan/16]);
write_data(table[zhufan%16]);
write_com(0x96);
write_data(table[kefan/16]);
write_data(table[kefan%16]);
}
else
{
write_com(0x85);
for(i=0;i<4;i++)
write_data(jiadui[i]);
write_com(0x81);
for(i=0;i<4;i++)
write_data(yidui[i]);
write_com(0x94);
write_data(table[zhudui/10]);
write_data(table[zhudui%10]);
write_com(0x92);
write_data(table[kedui/10]);
write_data(table[kedui%10]);
write_com(0x96);
write_data(table[zhufan/16]);
write_data(table[zhufan%16]);
write_com(0x90);
write_data(table[kefan/16]);
write_data(table[kefan%16]);
}
write_com(0x8c);
write_data(table[fen/10]);
write_data(table[fen%10]);
write_data(':');
write_data(table[miao/10]);
write_data(table[miao%10]);
write_data(' ');
write_data(table[msc24/10]);
write_data(table[msc24%10]);
if(TR0==1)
{
write_com(0x98);
for(i=0;i<6;i++)
write_data(bisaizhong[i]);
}
else
{
write_com(0x98);
for(i=0;i<6;i++)
write_data(zantingzhong[i]);
}
write_com(0x9c);
for(i=0;i<8;i++)
write_data(putongmoshi[i]);
if(flang==1)
{
TR0=0;
flang=0;
if(jie<4)
{
beep=0;
delay(7000);
beep=1;
}
else
{
beep=0;
delay(15000);
beep=1;
}
fen=10;
miao=0;
msc24=24;
jie++;
if(jie>4)
{
jie=4;
}
switch(jie)
{
case 1: //第一节
write_com(0x88);
for(i=0;i<6;i++)
write_data(diyijie[i]);
break;
case 2:
write_com(0x88);
for(i=0;i<6;i++)
write_data(dierjie[i]);
break;
case 3: //第三节
write_com(0x88);
for(i=0;i<6;i++)
write_data(disanjie[i]);
break;
break;
case 4: //第四节
write_com(0x88);
for(i=0;i<6;i++)
write_data(disanjie[i]);
break;
}
if(jie>4) //比赛时间到
{
beep=0;
delay(35000);
beep=1;
}
else
{
beep=0;
delay(35000);
beep=1;
}
}
}
void deal_with()//判断时间,转换处理数据
{
uchar i,j,k,temp;
k=1;
for(j=0;j<4;j++) //、、一共32位数据
{
for(i=0;i<8;i++)
{
temp=temp>>1;
if(irdate[k]>7)
{
temp=temp|0x80;
}
k++;
}
irbyte[j]=temp;
}
}
void qing_ling()//暂存数据清楚
{
uchar i;
for(i=0;i<33;i++)
irdate[i]=0;
for(i=0;i<4;i++)
irbyte[i]=0;
}
void anjian() //按键检测
{
if(irdateok==1)//解码成功
{
irdateok=0;
deal_with();
}
//////////////////////////////////////////////////数据判断,处理
key_num=irbyte[2];
if(irbyte[2]==zhujia1){ zhudui++; TR1=0; msc24=24; } // 主队加一分
if(irbyte[2]==zhujia2){ zhudui+=2; TR1=0; msc24=24; } // 主队加两分
if(irbyte[2]==zhujia3){ zhudui+=3; TR1=0; msc24=24; } // 主队加三分
if(irbyte[2]==zhujian1){ if(zhudui>0)zhudui--; TR1=0; msc24=24; }
if(irbyte[2]==zhujian2){ if(zhudui>1)zhudui-=2; TR1=0; msc24=24; }
if(irbyte[2]==zhujian3){ if(zhudui>2)zhudui-=3; TR1=0; msc24=24; }
if(irbyte[2]==kejia1){ kedui++; TR1=0; msc24=24; } // 客队加一分
if(irbyte[2]==kejia2){ kedui+=2; TR1=0; msc24=24; } // 客队加两分
if(irbyte[2]==kejia3){ kedui+=3; TR1=0; msc24=24; } //客队加三分
if(irbyte[2]==kejian1){ if(kedui>0)kedui--; TR1=0; msc24=24; }
if(irbyte[2]==kejian2){ if(kedui>1)kedui-=2; TR1=0; msc24=24; }
if(irbyte[2]==kejian3){ if(kedui>2)kedui-=3; TR1=0; msc24=24; }
if(irbyte[2]==zf1){ zhufan++; TR1=0; msc24=24; }
if(irbyte[2]==kf1){ kefan++; TR1=0; msc24=24; }
if(irbyte[2]==zanting){TR1=0;}
if(irbyte[2]==kaishi){TR1=1;}
if(irbyte[2]==qingling){msc24=24;}
if(irbyte[2]==qingping){zhudui=0;kedui=0;zhufan=0;kefan=0;TR1=0; msc24=24; beep=1; fen=10;miao=0;}
qing_ling();
}
void main()
{
xitonginit();
lcd_init();
while(1)
{
xianshi();
anjian();
}
}
void temer1() interrupt 3 //定时器0 中断函数
{
TH1=15;
TL1=0;
num++;
if(num==16)
{
num=0;
miao--;
if(miao<0)
{
fen--;
miao=59;
if(fen<0) flang=1;
}
//if(ql)
msc24--;
if(msc24==0) //24秒后暂停
{
TR1=0;
msc24=24;
beep=0;
delay(3500);
beep=1;
}
}
}
void T0_time() interrupt 1
{
irtime++;
}
void int0() interrupt 0 // 以下解码程序是固定
{
if(irflag==1)
{
if(irtime>32)
{
bitnum=0;
}
irdate[bitnum]=irtime;
irtime=0;
bitnum++;
if(bitnum==33)
{
bitnum=0;
irdateok=1;
}
}
else
{
irflag=1;
irtime=0;
}
}
?
1002925094