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

📄 myremotereception.bak

📁 这是符合国家一级汉字标准的汉字显示液晶模块程序
💻 BAK
📖 第 1 页 / 共 2 页
字号:
		}	
	}	
}


/*
** Function name: LEAD_H	03-6-24 16:44
**
** Description:
**	       The function is to process leader high detection.
**
** Input parameters:
**	            no
**
** Output parameters:
**	             no
**
** Return value:
**	        no		
*/
void LEAD_H()
{
	Uchar TM1Cnt;
	
	if(!g_btIR)		//level check g_btIR = 1:noise
	{
		Delay100usIR();		//100us wait
		
		if(!g_btIR)
		{	
			TM1Cnt = CR_READ();	
				
			//1 clock is 0.2us
      //Timer value read: 1.8ms - 100us* 2 -160clocks(edge detection ->
      // timer start)                            
			if(TM1Cnt >= 0x1e)		
			{
				//5ms - 100us * 2 - 160clocks(edge detection -> timer start)
				if(TM1Cnt < 0x5c)		
				{
					if(TM1Cnt > 0x35 )	//normal signal(3ms - 100us * 2)
					{
						s_g_SELMODE = 3;	//Data read mode
					}
					else
					{
						s_g_SELMODE = 4;	//Repeat detection mode
						
						INTM0 = 0xa4;	//INTP0 is rising edge interrupt
					}
				}
				else
				{
					S_M0SET();
				}
			
			}
			else
			{
				S_M0SET();
			}			
		}
		
	}
}


/*
** Function name: CDCODE
**
** Description:
**	       The function is to read Custom/Data CODE.
**
** Input parameters:
**	            no
**
** Output parameters:
**	             no
**
** Return value:
**	        no		
*/
void CDCODE()
{
	Uchar TM1Cnt;
	
	static sreg Uchar s_tempByte = 0;		//s_tempByte -- assigned temporarily  
																		  //to code by byte

  //s_tempCodes[0] -- custom code; s_tempCodes[1] -- custom code inverted;
  //s_tempCodes[2] -- data code; s_tempCodes[3]-- data code inverted	
	static sreg Uchar s_tempCodes[4];		
   
  //s_byteCntAccepted -- byte counts that have been accepted  						
  static sreg Uchar s_byteCntAccepted; 
 	
  //s_bitCntAccepted -- bit counts that have been accepted				
	static sreg Uchar s_bitCntAccepted;			
	
	if(!g_btIR)		//Level check g_btIR = 1:noise 	03-6-24 16:50
	{
		Delay100usIR();		//100us wait
		
		if(!g_btIR)		//03-6-24 16:50
		{
			TM1Cnt = CR_READ();
			
			//Custom code/data code is 1 or 0 when 0.5ms =< valid time =< 2.5ms
      //Timer value read: 0.5ms - 100us * 2 - 190 clocks(edge detection ->
      //timer start)
			if(TM1Cnt >= 0x4)		
			{				
				//0x2b is changed to 2e. 03-6-27 15:06
				//Timer value read: 2.5ms - 100us * 2 - 190 clocks(edge detection 
        //-> timer start)
				if(TM1Cnt < 0x2e)		
				{									    							        					       
				  //Custom code/data code is 1 when 1.8ms =< valid time =< 2.5ms
				  //Timer value read:1.8ms - 100us * 2 - 190 clocks(edge detection
          //-> timer start)       						           
			    if(TM1Cnt >= 0x1e)		
					{
						s_tempByte |= 0x80;		//bit = 1						
					}	
					
					if (s_bitCntAccepted < 7)
					{
						s_tempByte >>= 1;          // Shift right one bit																	
					}
					
				  s_bitCntAccepted++;	//Counter for bits is added by 1
				       				       					       					       				       					       				       					       				        				       
				  if(8 == s_bitCntAccepted)
			    {	
			    	s_bitCntAccepted = 0;
			    					    						    			
			    	s_tempCodes[s_byteCntAccepted++] = s_tempByte;
			    			
			    	s_tempByte = 0;			    						    			
			    			
			    	if(s_byteCntAccepted > 3)		//Counter for bytes is full.
			    	{
			    		s_byteCntAccepted = 0;
			    				
			    			if(CUSTOMER_CODE == s_tempCodes[0])
			    			{
			    				if((CUSTOMER_CODE ^ s_tempCodes[1])== 0xff)
			    				{
			    						if((s_tempCodes[2] ^ s_tempCodes[3]) == 0xff)
			    						{
												//g_TempRMDATA -- (Valid data storage area)where
                        //the ReMote input DATA is saved.
			    							g_TempRMDATA = s_tempCodes[2];		
			    							
			    							g_btIPDTFG = 1;
			    							
												//g_btRPT -- RePeaT(flag for repeat valid time)
			    							g_btRPT = 0;	
			    							
										    g_btRMDTSET = 0; //g_btRMDTSET -- ReMote DaTa SET	
										
										    s_g_btRMDTOK = 0;
										
										    S_M5SET();	//Error data detection mode setting
									    }		    										    									    						
			    						else
					    				{
					    					S_M0SET();
					    				}
			    					}
			    					else
				    				{
				    					S_M0SET();
				    				}
			    				}
			    				else
			    				{
			    					S_M0SET();
			    				}
			    			}			    					    	
			    		}
			    	}					        				    										
				else
				{
					S_M0SET();
				}
			}
			else
			{
				S_M0SET();
			}						
		}
	}
}

/*
** Function name: REPCD
**
** Description:
**	       The function is to detect repeat code.
**
** Input parameters:
**	            no
**
** Output parameters:
**	             no
**
** Return value:
**	        no		
*/
void REPCD()
{
	Uchar TM1Cnt;
	
	if(g_btIR)		//Level check g_btIR = 1:noise  03-6-24 16:51
	{
		Delay100usIR();		//100us wait
		
		if(g_btIR)		
		{
			if(s_g_btRMDTOK)	//Is valid data present?
			{	
				TM1Cnt = CR_READ();
				
				//Timer value read: 1ms - 100us*2 - 190 clocks(edge detection ->
        //timer start)						
				if(TM1Cnt <= 0xf)		
				{
					g_btRPT = 1;
				
					/*	//2003-10-31 16:32
					s_g_btRMDTOK = 0;	//Input signal check after the end of data
					
					g_btRMDTSET = 0;
					*/
					
					S_M5SET();					
				}
				else
				{
					S_M0SET();	//Set to leader(low) detection mode.
				}
			}
			else
			{
				S_M0SET();	//Set to leader(low) detection mode.
			}
			
		}
	}
}

/*
** Function name: ENDCHK
**
** Description:
**	       The function is to detect error data.
**
** Input parameters:
**	            no
**
** Output parameters:
**	             no
**
** Return value:
**	        no		
*/
void ENDCHK()		//Error data detection processing	03-6-24 16:53
{
	if(!g_btIR)		//Level check g_btIR = 0:noise
	{
		Delay100usIR();		//100us wait
		
		if(!g_btIR)
		{
			g_btIPDTFG = 0;	//Error data input
			
			g_btRPT = 0;	//Input signal invalid
			
			S_M0SET();	//Set to leader(low) detection mode.
		}
	}
}

/*
** Function name: S_M0SET
**
** Description:
**	       The function is to Set registers before Selecting Mode0-leader
**         (low) detection mode.
**	       Set 8bitTimer1 to 1.5 ms.
**	       Set s_g_SELMODE to 0, i.e. leader(low) detection mode.
**	       Disable INTP0 interrupt.
**
** Input parameters:
**	            no
**
** Output parameters:
**	             no
**
** Return value:
**	        no		
*/
void S_M0SET()		
{
	TMC01 =	0x02;	//Operation disabled(TM1 is cleared to 0.).	
	CR01 = 0x1c;	
	TMC01 =	0x82;	//8bitTimer1 is set to 1.5ms and starts.
	
	s_g_SELMODE = 0;	//Leader(low) detection mode.
	
	PMK0 = 1;	//Disable INTP0
}

/*
** Function name: S_M5SET
**
** Description:
**	       The function is to set error data detection mode.
**
** Input parameters:
**	            no
**
** Output parameters:
**	             no
**
** Return value:
**	        no		
*/
void S_M5SET()
{
	//Counter for 250-ms measurement ?? 250/1.5 =167 不是173啊?
	s_g_RPTCT = 173;	
	
	s_g_SELMODE = 5;	//End of data input mode
	
	s_g_RMENDCT = 3;	//Counter for no input verification
	
	TMC01 =	0x02;	//Operation disabled(TM1 is cleared to 0.).	
	CR01 = 0x1c;	
	TMC01 =	0x82;	//8bitTimer1 is set to 1.5ms and starts.
}


/*
** Function name: CR_READ
**
** Description:
**	       The function is to READ timer CounteR value.
**		     是不是该函数可以再优化TM1CntValue变量局部化????
**
** Input parameters:
**	            no
**
** Output parameters:
**	             no
**
** Return value:
**	        no		
*/
Uchar CR_READ()
{
	Uchar TM1CntValue = 0;
	
	TM1CntValue = TM01; 	//TM1CntValue is assigned by TM1 Count Value.
	
	TCE01 = 0;	//Stop timing operation
	
	TCE01 = 1;	//Timer starts.
	
	return TM1CntValue;
}


/*
** Function name: Delay100usIR
**
** Description:
**	       Used for delaying 100us.
**
** Input parameters:
**	            no
**
** Output parameters:
**	             no
**
** Return value:
**	        no		
*/
void Delay100usIR()		//需要用示波器测量,延时为102us,手算88.8us
{
	Uchar cnt = 11;
     
	while(cnt != 0)
	{
		cnt--;
	}
}

⌨️ 快捷键说明

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