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

📄 normod.c

📁 对遥控器PT2262编码芯片进行解码的源程序。已经在多个产品中使用。
💻 C
字号:
/****************************************************************************
【文  件  名  称】NORMOD.C
【功  能  描  述】
【程  序  版  本】
****************************************************************************/

//***************************************************************************

#include <REG2051.H>
#include "INC\SM89516A.H"
#include "INC\DECLARE.H" 
#include "INC\EXTERN.H"	
#include "INC\V24INT.H"
#include "INC\IOMOD.H"


#define Open_Clock()  TH0 = 0;TL0 = 0;TR0 = 1
#define Clear_Clock() TH0 = 0;TL0 = 0;TF0 = 0

bit  Wx_Signal_Last;
bit  Line1_Last,Line2_Last,Line3_Last,Line4_Last;
bit  Line1_Val,Line2_Val,Line3_Val,Line4_Val,NO_AC,LOW_VOL;

//***************************************************************************

/****************************************************************************
函数名   :Decode   
函数参数 :    
返回值   :   
功能描述 :   
创建日期 :
修改日期 :
****************************************************************************/
BYTE Decode()
{
	BYTE temp_code[4][3],bit_num = 0,code_num=0,j,temp_th0,result = 0; 	
	Clear_Clock();
	while(1)
	{  		
		if (V24_Inp_Ptr != V24_Out_Ptr)return 0;
		
		if(Wx_Signal_Last!= Wx_Signal)
		{
			temp_th0 = TH0;	 	
		    Clear_Clock(); 		
			Wx_Signal_Last = Wx_Signal;		
			if (Wx_Signal_Last == 0){	
				if (temp_th0 > 0x10){
					bit_num = 0;
					code_num++;
					if(code_num>3){
						return 0;
					} 
					//Watchdog_Reset();
				} 
				else
				{
					temp_code[code_num][bit_num>>3]<<=1;								
					if(temp_th0==0){
						temp_code[code_num][bit_num>>3]++;
					}  				
					
					bit_num++;					
					if (bit_num == 24)
					{							
						bit_num = 0;
						if (code_num > 0)
						{
							for(j=0;j<code_num;j++)
							{
								if((temp_code[j][0]==temp_code[code_num][0])
							     &&(temp_code[j][1]==temp_code[code_num][1])
								 &&(temp_code[j][2]==temp_code[code_num][2]))
								{
								   	Receive_Code[0] = temp_code[code_num][0];
									Receive_Code[1] = temp_code[code_num][1];
									Receive_Code[2] = temp_code[code_num][2];  
									return 1;									
								}											
							}
							
							if (code_num > 2){  							 								
								return 0;
							}						
						}
					}				
				} 			
			}
		}
		
		if(TH0 > 0x2E) return 0;			
	} 
}


/****************************************************************************
名称:    Normal_Mod
参数:    无
返回值:   无
描述:    
创建日期:
修改日期:
****************************************************************************/
void Normal_Mod()
{	
   	
	Work_Mode = 0;
   	Wx_Signal_Last = Wx_Signal;	 
	Line1_Val      = LINE1;
	Line1_Last     = LINE1;
	Line2_Val      = LINE2;
	Line2_Last     = LINE2;	
	Line3_Val      = LINE3;
	Line3_Last     = LINE3; 
	Line4_Val      = LINE4;
	Line4_Last     = LINE4;
	NO_AC          = NOAC;
	LOWVOL         = LOWVOL;        
	Open_Clock();
	

	while(1)
	{
		//Watchdog_Reset();		
		
		if(Wx_Signal_Last!= Wx_Signal)
		{
			Wx_Signal_Last = Wx_Signal;	
			if(TH0>0x10)	           //待解码的信号时序:6ms(0X14)时间的高电平+(信号内容),7个这样的周期,
			{						   //加上结束符大约360ms,
				if(Wx_Signal_Last==0)
				{	
					if(Decode()==1){
						//对比已经存在的码表  				
						if(Work_Mode == 0){
							Analyse_Code();							
						}else{
						 	//学习新的编码
						 	Write_Code();						 
						 	Work_Mode = 0;
						}				
					} 												
				} 				 			
							
			} 		
			Clear_Clock();						
		}	

		if(Read_V24()==1){
			if((Data_Rec_Temp[0]=='*')&&(Data_Rec_Temp[1]=='#')&&(Data_Rec_Temp[2]=='8')){
				Handle_Mcu1_Data();
			} 
		}

		//检测有线1
		if (LINE1!= Line1_Last)
		{
			Delay_Nms(10);
			if(LINE1!= Line1_Last)
			{
				Line1_Last = LINE1;
				if(Line1_Last != Line1_Val)
				{
					Send_Str("**9201\r\n");
				}
			}
		}

		if (LINE2!= Line2_Last)
		{
			Delay_Nms(10);
			if(LINE2!= Line2_Last)
			{
				Line2_Last = LINE2;
				if(Line2_Last != Line2_Val)
				{
					Send_Str("**9202\r\n");
				}
			}
		}

		if (LINE3!= Line3_Last)
		{
			Delay_Nms(10);
			if(LINE3!= Line3_Last)
			{
				Line3_Last = LINE3;
				if(Line3_Last != Line3_Val)
				{
					Send_Str("**9203\r\n");
				}
			}
		}
	
		if (LINE4!= Line4_Last)
		{
			Delay_Nms(10);
			if(LINE4!= Line4_Last)
			{
				Line4_Last = LINE4;
				if(Line4_Last != Line4_Val)
				{
					Send_Str("**9204\r\n");
				}
			}
		}

	/*	if(NO_AC != NOAC)
		{
			Delay_Nms(10);
			if(NO_AC != NOAC)
			{
				NO_AC = NOAC;
				if(NO_AC ==0)
				 	Send_Str("**92051\r\n");
				else
					Send_Str("**92053\r\n");
			}
		}	   */
		
	/*	if(LOW_VOL != LOWVOL)
		{
			Delay_Nms(10);
			if(LOW_VOL != LOWVOL)
			{
				LOW_VOL = LOWVOL;
				if(LOW_VOL ==0)
				 	Send_Str("**92061\r\n");
				else
					Send_Str("**92063\r\n");
			}
		}*/	
	}  
}

⌨️ 快捷键说明

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