本帖最后由 大明哥 于 2024-6-4 14:57 编辑
做了一个万能红外控制器,只是小小功能,能够学习任何红外码,然后学习成功之后 ,再发送出去,这样就可以控制任何需要用红外控制的机器,比如空调,电视机,投影,功放等,这里我只是做了一个空调的控制,大家,需要可以自己去拓展,用了一个红外模块通过串口4和T5L进入一个通信。有兴趣的,可以看下。 效果图视频如下: https://v.youku.com/v_show/id_XNjQwMDk1NjM5Ng==.html
界面如下
代码如下:
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);//关闭触摸按键
}
|