STC15单片机红外遥控编码采集在LCD1602上显示程序.docx
《STC15单片机红外遥控编码采集在LCD1602上显示程序.docx》由会员分享,可在线阅读,更多相关《STC15单片机红外遥控编码采集在LCD1602上显示程序.docx(16页珍藏版)》请在冰豆网上搜索。
![STC15单片机红外遥控编码采集在LCD1602上显示程序.docx](https://file1.bdocx.com/fileroot1/2022-10/24/f5e8ab75-58df-48aa-b023-d2b726f9ae71/f5e8ab75-58df-48aa-b023-d2b726f9ae711.gif)
STC15单片机红外遥控编码采集在LCD1602上显示程序
敬告:
没有51单片机基础的人请慎重下载
高质量实用性51单片机STC15W系列程序(5),STC8A系列可参考
STC15单片机红外遥控编码采集在LCD1602上显示程序
注:
此程序比较复杂,但非常有助于提高编程水平,程序中有些小技巧希望大家能够学会用法/*******************************************/
//main.c
#include"Library.h"
voidValToStr(unsignedchar*str,unsignedchar*tmp);
voidmain()
{
unsignedcharrec_buf[4];
unsignedchartmpbuf[4];
unsignedcharstrbuf[8];
bitfra;
P5M1&=0xDF;P5M0&=0xDF;
P2M1&=0xE5;P2M0&=0xE5;
P0M1=0x00;P0M0=0x00;
Timer0_config();
LCD1602_init();
LCD1602_wBytes(0,0,"usercode:
",sizeof("usercode:
")-1);
LCD1602_wBytes(0,1,"keycode:
",sizeof("keycode:
")-1);
EA=1;
while
(1)
{
fra=Rep_pro(rec_buf);
if(fra)
{
fra=0;
tmpbuf[0]=rec_buf[0];
tmpbuf[1]=rec_buf[2];
tmpbuf[2]=rec_buf[3];
tmpbuf[3]=rec_buf[1];
if((~tmpbuf[2])==tmpbuf[1])
{
ValToStr(strbuf,tmpbuf);
LCD1602_wBytes(10,0,strbuf,2);
LCD1602_wBytes(13,0,strbuf+6,2);
LCD1602_wBytes(10,1,strbuf+2,2);
LCD1602_wBytes(13,1,strbuf+4,2);
}
}
}
}
//voidValToStr(unsignedchar*str,unsignedchar*tmp)
//{
//str[0]=tmp[0]/10+'0';
//str[1]=tmp[0]%10+'0';
//str[2]=tmp[1]/10+'0';
//str[3]=tmp[1]%10+'0';
//str[4]=tmp[2]/10+'0';
//str[5]=tmp[2]%10+'0';
//str[6]=tmp[3]/10+'0';
//str[7]=tmp[3]%10+'0';
//
//}
voidValToStr(unsignedchar*str,unsignedchar*tmp)
{
if(((tmp[0]>>4)&0x0F)<=9)
{
str[0]=((tmp[0]>>4)&0x0F)+'0';
}
else
{
str[0]=((tmp[0]>>4)&0x0F)-10+'A';
}
if((tmp[0]&0x0F)<=9)
{
str[1]=(tmp[0]&0x0F)+'0';
}
else
{
str[1]=(tmp[0]&0x0F)-10+'A';
}
if(((tmp[1]>>4)&0x0F)<=9)
{
str[2]=((tmp[1]>>4)&0x0F)+'0';
}
else
{
str[2]=((tmp[1]>>4)&0x0F)-10+'A';
}
if((tmp[1]&0x0F)<=9)
{
str[3]=(tmp[1]&0x0F)+'0';
}
else
{
str[3]=(tmp[1]&0x0F)-10+'A';
}
if(((tmp[2]>>4)&0x0F)<=9)
{
str[4]=((tmp[2]>>4)&0x0F)+'0';
}
else
{
str[4]=((tmp[2]>>4)&0x0F)-10+'A';
}
if((tmp[2]&0x0F)<=9)
{
str[5]=(tmp[2]&0x0F)+'0';
}
else
{
str[5]=(tmp[2]&0x0F)-10+'A';
}
if(((tmp[3]>>4)&0x0F)<=9)
{
str[6]=((tmp[3]>>4)&0x0F)+'0';
}
else
{
str[6]=((tmp[3]>>4)&0x0F)-10+'A';
}
if((tmp[3]&0x0F)<=9)
{
str[7]=(tmp[3]&0x0F)+'0';
}
else
{
str[7]=(tmp[3]&0x0F)-10+'A';
}
}
/*******************************************/
//红外程序
//Infrared.c
/**********************************
guidecode:
9mslow+4.5mshigh
bit0:
560uslow+560ushigh
bit1:
560uslow+1.68mshigh
guidecode,usercode,userinversecode,keycode,keyinversecode,stopbit
**********************************/
#include"Library.h"
bitguideflag=1;
bitbitHH;
bitbitH;
bitbitM;
bitbitL;
bitflagH1;
//bitflagH2;
bitIR1;
bitIR2;
bitrep;
unsignedintcnt;
unsignedchartmpbuf[32];
bitframeflag;
bitbitval;
bitwin;
bitrep_back;
unsignedcharrecbuf[4];
bitInfrared_monitor()
{
bitack;
cnt++;
IR2=IR1;
IR1=inf;
if(IR2&&(!
IR1))
{
if(cnt>280)
{
IR2=0;
IR1=0;
cnt=0;
ack=0;
return0;
}
}
elseif((!
IR2)&&IR1)
{
if((cnt>=170)&&(cnt<=190))
{
flagH1=1;
}
else
{
return0;
}
}
if(flagH1)
{
if(IR2&&(!
IR1))
{
if((cnt>=260)&&(cnt<=280))
{
guideflag=0;
flagH1=0;
IR2=0;
IR1=0;
cnt=0;
ack=1;
}
}
}
returnack;
}
voidRec_bit()
{
cnt++;
IR2=IR1;
IR1=inf;
if(IR2&&(!
IR1))
{
if(cnt>50)
{
IR2=0;
IR1=0;
cnt=0;
return;
}
}
if((!
IR2)&&IR1)
{
if((cnt>=10)&&(cnt<=14))
{
bitH=1;
}
{
return;
}
}
if(bitH)
{
if(IR2&&(!
IR1))
{
if((cnt>=40)&&(cnt<=50))//2240
{
bitH=0;
IR2=0;
IR1=0;
cnt=0;
win=1;
bitval=1;
}
elseif((cnt>=20)&&(cnt<=25))//1120
{
bitH=0;
IR2=0;
IR1=0;
cnt=0;
win=1;
bitval=0;
}
}
}
//elseif(!
bitH)
//{
//
//}
//if(inf&&bitH)
//{
//}
//elseif((cnt>=40)&&(cnt<=50))//2240
//{
//bitH=0;
//cnt=0;
//win=1;
//bitval=1;
//}
//elseif((cnt>=20)&&(cnt<=25))//1120
//{
//bitH=0;
//cnt=0;
//win=1;
//bitval=0;
//}
}
unsignedcharRec_dat()
{
//bi