📄 remote.c
字号:
/*串行通信/红外线解码显示程序
广东工业大学自动化学院04级自动化3班 吴子洲
版权所有,如要转载,请注明出处*/
#define uchar unsigned char
#define uint unsigned int
#include <reg52.h>
uchar code tir[]={ //IR table
/*------0----1----2----3----4----5----6----7----8----9----a----b----c----d----e----f---*/
/*0*/ 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
/*1*/ 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
/*2*/ 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
/*3*/ 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
/*4*/ 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
/*5*/ 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
/*6*/ 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
/*7*/ 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
/*8*/ 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
/*9*/ 0x01,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
/*a*/ 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
/*b*/ 0x04,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x02,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
/*c*/ 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
/*d*/ 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
/*e*/ 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
/*f*/ 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x03,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
};
uchar tt; //infrared ray time couter
uchar ret; //char receive from serail port
uchar st; //infrared ray start
uchar irc; //ir counter
uint su; //ir resut
uchar kir;
void s_ini(void) ///system initialization
{tt=0;
st=0;
kir=0xff;
IT1=1; //int1 falling cause interrupt
TMOD=0x22; //timer 1 and timer 0 all as auto reload timer
IE=0x86; //enale timer0 and int1 interrupt
//IP=0x40; //int1 interrupt as priority interrupt
SCON=0x53; //serial port mode=1; enable to recive and receive and sent inteerupt
TH1=0xFD; //baund rate=9600bps
TH1=0xFD;
TH0=0x48; //200us timer
TL0=0x48;
TR0=1;
TR1=1;
}
void main(void)
{uchar ky;
s_ini();
while(1)
{ky=kir;
kir=0xff;
if(ky==0x01)
SBUF=0xE1;
else if(ky==0x02)
SBUF=0xE2;
else if(ky==0x03)
SBUF=0xE3;
else if(ky==0x04)
SBUF=0xE4;
}
}
void int1(void) interrupt 2 //interrupt int1 service
{uchar tm;
uchar t1,t2;
tm=tt;
tt=0;
if(st==1)
{su*=2;
irc++;
if(irc>=16)
{if(tm>8)
su+=1;
}
if(irc>=32)
{t1=su/256;
t2=su%256;
irc=0;
if(t1=~t2)
{t2=tir[t1];
kir=t2;
SBUF=t2;
}
else
kir=0xff;
}
}
if(tm==0x43||tm==0x44) //start condition
st=1,irc=0,su=0;
}
void timer0(void) interrupt 1 //interrupt timer0 service
{tt++;
}
void com(void) interrupt 4 //serial port interrupt serice
{if(RI==1) //receive a char from serail port
{ret=SBUF;
RI=0;
}
else if(TI==1) //had sent a char
TI=0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -