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

📄 ir_panel.c

📁 本人以前做的一个DVD+TV 项目
💻 C
字号:
#include "reg51.h"
#include "global.h"
#include "ir_panel.h"
//***********************************
#define IR_WAIT_NEW_CODE        0
#define IR_WAIT_LEAD_CODE       1
#define IR_READ_CUSTOM_CODE     2
#define IR_READ_SUB_CUSTOM_CODE 3
#define IR_READ_DATA_CODE       4
#define IR_READ_DATA_CODE_INV   5
#define IR_READ_REPEAT_CODE     6

void int0_ir()interrupt 2 using 0			//INT0
{
	TR0=0;
	EX1=0;
	vIrRecv();
	TH0=0;
	TL0=0;
	TR0=1;
	EX1=1;
}
void IrInit(void) 
{
  // reset IR related variable
  _bIRStatus = 1; /* IR_WAIT_NEW_CODE */
  _bIRBitCnt = 0;
  _bIRKeyBuf = 0;
  return;
}
void vIrRecv()
{
	switch(_bIRStatus)
	{
		case IR_WAIT_NEW_CODE:
			_bIRStatus=IR_WAIT_LEAD_CODE;
			break;
		case IR_WAIT_LEAD_CODE:
#ifdef IR_16MHZ
				if( TH0==0x46||TH0==0x3a)		//13.5ms 11.25ms  4650  3a98
#else
#ifdef IR_12MHZ
				if( TH0==0x34||TH0==0x2b||TH0==0x2c)		//13.5ms   34bc	2bf2
#else  //
#ifdef IR_6MHZ
				if( TH0==0x1a||TH0==0x15||TH0==0x16)		//13.5ms   1a5e 15f9
#else	 //3.58MHZ			
				if( TH0==0x0f||TH0==0x10)		//13.5ms   0FBB 
#endif   //IR_6MHZ				
#endif  //IR_12MHZ
#endif //IR_16MHZ
				{
				_bIRStatus=IR_READ_CUSTOM_CODE;
				
				}
				else
				IrInit();	
			break;	
		case 	IR_READ_CUSTOM_CODE:
			_bIRBitCnt++;
			_bIRKeyBuf>>=1;
#ifdef IR_16MHZ
				if(TH0==0x0b) 		//2.25ms   0bb8
#else
#ifdef IR_12MHZ
				if( TH0==0x08)		//2.25ms    08ca
				
#else
#ifdef IR_6MHZ
				if( TH0==0x04)		//2.25ms  0465
#else	 //3.58MHZ			
				if( TH0==0x02)		//2.25ms   029f
#endif   //IR_6MHZ												
#endif  //IR_12MHZ
#endif  //IR_16MHZ
						_bIRKeyBuf|=0x8000;	
#ifdef IR_16MHZ
				else if(TH0==0x05) 		//1.25ms   05dc
#else
#ifdef IR_12MHZ
				else if(TH0==0x04)		//1.25ms   0465
#else
#ifdef IR_6MHZ
				else if(TH0==0x02)		//1.25ms   0233
#else	 //3.58MHZ			
				else if( TH0==0x01)			//1.25ms  0175 
#endif   //IR_6MHZ								
#endif
#endif									
						_bIRKeyBuf&=0x7fff;	
				else		
					IrInit();
				if(_bIRBitCnt==16)
				{
					if(_bIRKeyBuf==IR_SYSTEM_CODE)	
						{
							_bIRStatus=IR_READ_SUB_CUSTOM_CODE;
							_bIRKeyBuf=0;
						}
					else		
						IrInit();				
				}		
			break;	
		case  IR_READ_SUB_CUSTOM_CODE:
			_bIRBitCnt++;
						_bIRKeyBuf>>=1;
#ifdef IR_16MHZ
				if(TH0==0x0b) 		//2.25ms   0bb8
#else
#ifdef IR_12MHZ
				if( TH0==0x08)		//2.25ms    08ca
#else
#ifdef IR_6MHZ
				if( TH0==0x04)		//2.25ms  0465
#else	 //3.58MHZ			
				if( TH0==0x02)		//2.25ms   029f
#endif   //IR_6MHZ				
#endif   //IR_12MHZ				
#endif  //IR_16MHZ	
						_bIRKeyBuf|=0x8000;	
#ifdef IR_16MHZ
				else if(TH0==0x05) 		//1.25ms   05dc
#else
#ifdef IR_12MHZ
				else if(TH0==0x04)		//1.25ms   0465
#else
#ifdef IR_6MHZ
				else if(TH0==0x02)		//1.25ms   0233
#else	 //3.58MHZ			
				else if( TH0==0x01)			//1.25ms  0175 
#endif   //IR_6MHZ												
#endif
#endif									
						_bIRKeyBuf&=0x7fff;	
				else		
					IrInit();
				if(_bIRBitCnt==32)
				{
						_IR_key=_pbIRKeyTbl[_bIRKeyBuf&0x00ff];
					
						_fgIRKeyValid=TRUE;
						IrInit();
				}	
				break;
			}	
}
void Timer1()interrupt 3 using 0	
{

if(player_status==0)  //PLAYER_STATUS_DVD)
{
	ir_conv_timer=1;	
	f_timer_2s_ch=2;
}	
else
{	
	timer1_counter++;
	timer1_counter1++;
	
	timer1_counter_ch++;//for osd
	if(f_timer_2s_ch==10)timer1_counter_ch=0;
	if(f_timer_2s==1)timer1_counter=0;
	if(timer1_counter1==125){
		timer1_counter1=100;	}
		
	if(timer1_counter==100){
	f_timer_2s=1;timer1_counter=0;}
	
	if(timer1_counter_ch==250&&f_timer_2s_ch==0){
	f_timer_2s_ch=1;timer1_counter_ch=0;}
	if(timer1_counter_ch==250&&f_timer_2s_ch==1){
	f_timer_2s_ch=2;timer1_counter_ch=0;}

	TH1=0xf8 ; //0xD8;//2000*4   <8ms
	TL1=0x2f;   //0xEF;
}	
	
	
}

⌨️ 快捷键说明

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