|
【开源】万能红外控制器
和大家分享一个万能红外控制器,通过红外模块可以学习任何红外码,这样就可以控制任何需要用红外控制的机器,比如空调、电视机、投影仪、功放机等。这里做了一个空调的控制方案,采用T5L串口4与红外模块进行通讯,大家有需要可以自己去拓展。
效果图视频如下:
- <font face="宋体">代码如下:
- INIT_CPU();
- T2_Init();
- UART4_Init();
- EA=1;
- void Process(void)
- {
- OneMsHandle();
- TenMsHandle();
- }
- bool uartHandle(u8 *Tdata,u16 len)
- {
- u8 writedata[2]={0,0};
- u8 PressKeyI[] ="完成 ";
- u8 PreMacClose[]="请再按下关机键 ";
- if(!ReadYaoKongOper)
- return false;
- if(Tdata[0]!=0x68)
- return false;
- switch(Tdata[1])
- {
- case 8://正常应答,可以不管
- break;
- case 0X0A://正常应答,可以不管
- // default://返回已经弄好的学习码
- memset(&IR_CmdPack,0,sizeof(IR_CmdPack));
- IR_CmdPack.Tok=0x5a;
- IR_CmdPack.len=len;
- memcpy(IR_CmdPack.cmddata,Tdata,len);
- Write_Dgusii_Vp(0x5000,(u8*)&IR_CmdPack,sizeof(IR_CmdPack_s)/2);
- T5L_Flash(WRITE_MOD,0x5000,0x800+2048*(ReadYaoKongOper-1),sizeof(IR_CmdPack_s)/2);
-
- if(ReadYaoKongOper==1)
- {
- Write_Dgusii_Vp(0x2000,PreMacClose,strlen(PreMacClose)/2);
- SendLearnCodeId(7);
- ReadYaoKongOper=7;
- }
- else
- {
- ReadYaoKongOper=0;//操作完成
- Write_Dgusii_Vp(0x1200,writedata,1);//写显示logo
- Write_Dgusii_Vp(0x2000,PressKeyI,strlen(PressKeyI)/2);
- }
- // UART4_SendStr(Tdata,len);
- break;
- }
- return true;
- }
- void RecordPageKeyPress(void)
- {
- #if 1
- u8 TouchKey[2]={0,0};
- u8 writedata[2]={0,0};
- // u8 learnCode[]={0x68 ,0x08 ,0x00, 0xFF, 0x10 ,0x00 ,0x0F, 0x16};
- u8 PressKeyI[]="请按下遥控按键";
- u8 PreMachStart[]="请按下遥控开机键";
- Read_Dgusii_Vp(0x1210,TouchKey,1);
- if(TouchKey[1]==0)
- return;
- if(!ReadYaoKongOper && TouchKey[1]<7)
- { //只有未学习的时候,操作学习码
- SendLearnCodeId(TouchKey[1]);
- if(TouchKey[1]<=8)
- writedata[1]=1<<(TouchKey[1]-1);
- Write_Dgusii_Vp(0x1200,writedata,1);//写显示logo
- ReadYaoKongOper=TouchKey[1];
- if(ReadYaoKongOper!=1)
- Write_Dgusii_Vp(0x2000,PressKeyI,strlen(PressKeyI)/2);
- else
- Write_Dgusii_Vp(0x2000,PreMachStart,strlen(PreMachStart)/2);
- }
- TouchKey[1]=0;
- Write_Dgusii_Vp(0x1210,TouchKey,1);//关闭触摸按键
- #endif
- }
- void CtrPageKeyPress(void)
- {
- u8 TouchKey[2]={0,0};
- u8 sendcmd[]={0x68 ,0x08 ,0x00 ,0xFF ,0x12, 0x00 ,0x11, 0x16};
- u8 MachStart[]="已开机";
- u8 MachClose[]="已关机";
- Read_Dgusii_Vp(0x1300,TouchKey,1);
- if(TouchKey[1]==0)
- return;
- // printf("CtrPageKeyPress\r\n");
- if(TouchKey[1]<7)
- {
- memset(&IR_CmdPack,0,sizeof(IR_CmdPack));
- #if 0
- T5L_Flash(READ_MOD,0x5000,0x800+2048*(TouchKey[1]-1),sizeof(IR_CmdPack_s)/2);
- Read_Dgusii_Vp(0x5000,(u8*)&IR_CmdPack,sizeof(IR_CmdPack_s)/2);
- if(IR_CmdPack.Tok==0x5a)
- UART4_SendStr(IR_CmdPack.cmddata,IR_CmdPack.len);
- #else
- if(TouchKey[1]!=1)
- {
- sendcmd[5]=TouchKey[1]-1;
- sendcmd[6]=sendcmd[6]+sendcmd[5];
- }
- else
- {
- if(MachineST)
- {
- MachineST=0;
- TouchKey[1]=7;
- sendcmd[5]=TouchKey[1]-1;
- sendcmd[6]=sendcmd[6]+sendcmd[5];
- Write_Dgusii_Vp(0x2300,MachClose,strlen(MachClose)/2);
- }
- else
- {
- MachineST=1;
- sendcmd[5]=TouchKey[1]-1;
- sendcmd[6]=sendcmd[6]+sendcmd[5];
- Write_Dgusii_Vp(0x2300,MachStart,strlen(MachStart)/2);
- }
- }
- UART4_SendStr(sendcmd,sizeof(sendcmd));
- #endif
- // printf("IR_CmdPack.Tok:%d",IR_CmdPack.Tok);
- // UART4_SendStr(&IR_CmdPack,10);
- }
- TouchKey[1]=0;
- Write_Dgusii_Vp(0x1300,TouchKey,1);//关闭触摸按键
- }</font>
复制代码
备注说明:如需源码,请参考此链接:http://inforum.dwin.com.cn:20080/forum.php?mod=viewthread&tid=10416&_dsign=c58dffae
|
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有账号?立即注册
x
|