⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 irint.c

📁 car dvd tft t100 source
💻 C
字号:
//#ifdef INTERRUPT1
#include "reg51.h"
#include <intrins.h>
#include "Remote.h"

bit ir_enable;
uCHAR ir_data;

bit Filter13(bit le)
{
	bit r;
	r=INT1;
	if(le==1)
	{
		_nop_();
		_nop_();
		_nop_();
		r&=INT1;
		_nop_();
		_nop_();
		_nop_();
		r&=INT1;
	}
	else
	{
		_nop_();
		_nop_();
		_nop_();
		r|=INT1;
		_nop_();
		_nop_();
		_nop_();
		r|=INT1;
	}
	if(r==le)
		return 1;
	else
		return 0;
}
/*遥控接收在此中断程序内完成
  数据放在ir_data内*/
/************************************/
/*  Interrupt for IR subroutine     */
/*  external interrupt source INT0  */
/************************************/
void int1Remote(void) interrupt 2
{
/*    static uWORD IR_HEAD=20000;//	=	(XCLK_MCU*3/4);//10738//9000//7500
	static uWORD OFF_CODE=10000;//  =   (IR_HEAD/2);//5369//4500//3750
	uWORD OFF_REP;//	=	(IR_HEAD/4);//2684//2250//	1875
	uWORD REP_CODE;//	=	(IR_HEAD/16);//667//467
	uWORD DELTA ;//    = 	300;//250
	uWORD CODE_0_TIME;//=	(IR_HEAD/16);//667//557//467
	uWORD CODE_1_TIME;//=	(CODE_0_TIME*3);//2000//1670//1400*/
	register BYTE i;
	unsigned int count,count1;		/*计时变量*/
	unsigned int  temp0,temp1,ir_code=0;
	ir_enable=TRUE;
	TMOD=0x11;             /*timer 0 operate in 16 bit mode*/
	EX1=0;
	TL0=0;
	TH0=0;
	TR0=1;
	/************************************/
	/*   Detect IR Head                 */
	/************************************/
	do                /*Detect IR head 9mS*/
	{
		count=(TL0+TH0*256);   /*count :us unit */
		if(Filter13(1)==1) break;
	}while(count<=(IR_HEAD+DELTA));
	TR0=0;			/*停止计时*/
		count=(TL0+TH0*256);   /*count :us unit */
	
	if(Filter13(0)==1||((count<(IR_HEAD-DELTA*25))))//&&(IR_HEAD!=0xffff)))//||count<(7000))//IR_HEAD!=0xffff)       /*for some noise disturb IR*/
		{
		ir_enable=FALSE; /* no IR head or not suitable for Ir head*/
		EX1=1;
		TR0=1;
		return;
		}
	/************************************/
	/*   Detect OFF CODE     4.5mS      */
	/************************************/
	while(Filter13(0)==1);
	TR0=0;
	TL0=0;
	TH0=0;
	TR0=1;
	do                /*Detect IR OFF CODE*/
	{
		count=(TL0+TH0*256);   /*count :us unit */
		if(Filter13(0)==1) break;
	}while(count<(OFF_CODE+DELTA));
	count1=count;
 /*  if(IR_HEAD==0xffff)IR_HEAD	=	count*2;//10738//9000//7500
	OFF_CODE  =   IR_HEAD/2;//5369//4500//3750
	OFF_REP	=	(IR_HEAD/4);//2684//2250//	1875
	REP_CODE	=	(IR_HEAD/16);//667//467
	DELTA     = 	300;//250
	CODE_0_TIME=	(IR_HEAD/16);//667//557//467
	CODE_1_TIME=	(CODE_0_TIME*3);//2000//1670//1400*/
	TR0=0;
	count=(TL0+TH0*256);   /*count :us unit */
	if(count<=(OFF_CODE-DELTA*2))
	{
		/*重复码OFF=2.25*/
		if((count>(OFF_REP-DELTA)&&count<(OFF_REP+DELTA)))
		{
			TR0=0;
			TL0=0;
			TH0=0;
			TR0=1;
			do
			{
				count=(TL0+TH0*256);   /*count :us unit */
				if(Filter13(1)==1) break;
			}while(count<=(REP_CODE+DELTA));
			TR0=0;
			count=(TL0+TH0*256);   /*count :us unit */
			if(INT1==1)
			{
				TR0=0;
				if(ir_data==REMOTE_KEY_VO_DEC||ir_data==REMOTE_KEY_VO_INC||
				ir_data==REMOTE_KEY_DECR_F||ir_data==REMOTE_KEY_INCR_F||
				ir_data==REMOTE_KEY_DECR||ir_data==REMOTE_KEY_INCR)
				{
				ir_enable=TRUE;	/*注意:ir_data不变*/
				EX1=0;
				}
				else
				{
				ir_data=0;
				ir_enable=FALSE;
				EX1=1;
				TR0=1;
				}
				return;
			}
		}
		else
		{
			ir_enable=FALSE;   /*not suitable for off code*/
			EX1=1;
			TR0=1;
			return;
		}
	}
	/************************************/
	/*   Detect 16 bit address code     */
	/************************************/
	if(ir_enable==TRUE)
	{
		TMOD=0x11;           /*counter start with INT0 and TR0*/
		ir_code=0;		/*初始化变量*/
		for(i=0;i<16;i++)
		{
			while(INT1==0);
			TL0=0;
			TH0=0;
			TR0=1;
			do
			{
				count=(TL0+TH0*256);   /*count :us unit */
				if(Filter13(0)==1) break;
			}while(count<=(CODE_1_TIME+DELTA));	/*INT0为高电平时计时*/
			TR0=0;
			ir_code<<=1;
			if((count>(CODE_1_TIME-DELTA))&&(count<=(CODE_1_TIME+DELTA)))  /*detect 1 code  2.24mS-0.56mS=1.68mS*/
				ir_code++;
			else if((count>(CODE_0_TIME-DELTA))&&(count<=(CODE_0_TIME+DELTA)));  /*detect 0 code 1.12mS-0.56mS=0.56mS*/
			else
			{
			 	ir_enable=FALSE;
				TR0=1;
				break;           /*not suitable for address code */
			}
		}                /*end for*/
	}
	/************************************/
	/*   Detect 16 bit data code        */
	/************************************/
	if(ir_enable==TRUE&&ir_code==IR_SYSTEM_CODE)/**/
	{
		TMOD=0x11;           /*counter start with INT0 and TR0*/
		ir_code=0;
		for(i=0;i<16;i++)
		{
			while(INT1==0);
			TL0=0;
			TH0=0;
			TR0=1;
			do
			{
				count=(TL0+TH0*256);
				if(Filter13(0)==1) break;
			}while(count<=(CODE_1_TIME+DELTA));	/*INT0为高电平时计时*/
			TR0=0;
			//count=(TL0+TH0*256);   /*count :us unit */
			ir_code<<=1;
			if((count>(CODE_1_TIME-DELTA))&&(count<=(CODE_1_TIME+DELTA)))  /*detect 1 code 1.68mS*/
				ir_code++;
			else if((count>(CODE_0_TIME-DELTA)&&count<=(CODE_0_TIME+DELTA)));  /*detect 0 code 0.56mS*/
			else
			{
				ir_enable=FALSE;
				TR0=1;
				break;           /*not suitable for address code */
			}
		}                /*end for*/
		if(ir_enable==TRUE)
		{
			temp0=ir_code&0xff00;
			temp0=~temp0;
			temp0>>=8;
			temp1=ir_code&0x00ff;
			if(temp0!=temp1)
				ir_enable=FALSE;
			else
			{
				ir_data=(BYTE)(temp1);     /*true code effective*/
				#ifdef REMOTE_CODE
				ir_data=0xff-ir_data;
				ir_data=((ir_data<<4)&0xf0)|((ir_data>>4)&0x0f);
				ir_data=((ir_data<<2)&0xcc)|((ir_data>>2)&0x33);
				ir_data=((ir_data<<1)&0xaa)|((ir_data>>1)&0x55);
				#endif
				ir_enable=TRUE;            /*set ir flag*/
				EX1=0;
//				IR_HEAD	=	count1*2;
				return;
			}
		}
	}
	else
	{	ir_enable=FALSE;
	EX1=1;}
}

//#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -