文档视界 最新最全的文档下载
当前位置:文档视界 › 基于uPD6121LC7461MHT6222AS6122等红外编码芯片的解码程序(AT89S52)

基于uPD6121LC7461MHT6222AS6122等红外编码芯片的解码程序(AT89S52)

/*----------基于uPD6121/LC7461M/HT6222/AS6122等红外编码芯片的解码程序------------
作者:Benny
Email:89S53@https://www.docsj.com/doc/1110654544.html,
MCU: AT89S52
Crystal: 11.0592Mhz
*/
#include
#include "Atmel\REGX52.h"

#define uint unsigned int
#define uchar unsigned char
#define ulong unsigned long


uchar th1=0;
uchar tl1=0;

uchar int_0_times=0;
uchar times=0;


data uint T1_Count;// _at_ 0x8c; //保存T1的计数值

data ulong result _at_ 0x6f;

data uchar result1 _at_ 0x6f;
data uchar result2 _at_ 0x70;
data uchar result3 _at_ 0x71;
data uchar result4 _at_ 0x72;

bit flag=0;
void int_0() interrupt 0 using 3
{
int_0_times++; //记录中断次数
EA=0;
//TR0=0;
TR1=0;
if (int_0_times==1)
{
result=0;
times=0;
}
else if(int_0_times>2)
{ times++;
if (times>32)
{
//TR0=0;
TR1=0;
flag=1;
goto Quit;

}

T1_Count=TH1;
T1_Count<<=8;
T1_Count=T1_Count+TL1;
if (T1_Count>1750)
{//是"1"
result*=2;
result=result+1;
}
else if (T1_Count<1350)
{//是"0"
result*=2;
}
}
//TH0=0;TL0=0;
TH1=0;TL1=0;
//TR0=1;
TR1=1;
Quit:
EA=1;
}
void serial() interrupt 4 using 3
{
if (RI)
{
RI = 0;
if (SBUF==0x20)
{
flag=1; //如果键盘按下“空格”键,则发送当前result的值
}


}
else if (TI)
{TI=0;}
}

void initial(void)
{
PCON=0; //Stop WDT

/*Timer0 & Timer1 Initial*/
TMOD=0x19; //0001 1001B
TH0=0;TL0=0;TH1=0;TL1=0;

/*Timer2 Initial*/
SCON=0x50; //0101 0000B
RCAP2H=0xff; //XTAL=11.0592MHz,BaudRate=9600
RCAP2L=0xdc;
PCON|=0x80; //波特率加倍
T2CON=0x30; //0011 0000B 作为波特率发生器

/*Start the timers*/
IT0=1; //INT0为边缘触发方式
IE=0xb3; //1011 0011

TR2=1;
result=0;
}
void delay(void)
{
uint i;
for(i=0;i<150;i++);
}
void main(void)
{

initial();

while(1)
{ uchar i;
while(flag==0);
TR1=0;
if (result3 & result4)
{
SBUF=0xff;
}
else
{
SBUF=result1;while(TI==0);TI=0; // 发送用户码高8位
SBUF=result2;while(TI==0);TI=0; // 发送用户码低8位
SBUF=result3;while(TI==0);TI=0; // 发送键码
SBUF=result4;while(TI==0);TI=0; // 发送键码反码
}

result=0;
int_0_times=0;
times=0;
fl

ag=0;


}


}



相关文档