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

📄 mycommio.c

📁 这是符合国家一级汉字标准的汉字显示液晶模块程序
💻 C
📖 第 1 页 / 共 2 页
字号:
**         code.
**
** Input parameters:
**	            no
**
* * Output parameters:
**	             no
**
** Return value:
**	        no		
*/
void GetDataFromReception()
{	 				
	if(!ErrorRceptionCheck())			//Return if error occurs
	{															
		//ReceiveData();
		g_controlCode = *(g_p_bufReception + 1);
	 
	  //Is the variable useful in other section of the programme ?
	  g_byteLength = *(g_p_bufReception + 2);	
	  
	  g_deviceAddr = *(g_p_bufReception + 3);
	
		switch(g_controlCode)
		{
			case 1:
							g_custom0 = *(g_p_bufReception + 4);
              g_custom1 = *(g_p_bufReception + 5);
              g_custom2 = *(g_p_bufReception + 6);
              
              break;
              
              
      case 3:
							g_dataFormat = *(g_p_bufReception + 4);
							
							break;
							
			//....still have more..
							
			default:
							//g_p_bufReception = g_bufReception;	 
							break;   
		} 
		
		g_p_bufReception = g_bufReception;   
	}     	              
}



/*    
** Function name: Inter_SR                                                  
**
* Description:
**         The function is ISR - Interrupt Service Routine of reception 
**         completion interrupt.                                                
**
** Input parameters:
**	            no
**
* * Output parameters:
**	             no
**
** Return value:
**	        no		
*/
void Inter_SR()
{
//g_btReceptionEnd = 1;   //Set g_btReceptionEnd to 1 when Reception ends.
	static sreg Uchar s_receptionCnt = 0;
	
	Uchar valueObtained = 0; 
	
	//valueObtained = RXB00;
	
	//s_receptionCnt++;		//Where to put it?
	
	if(s_receptionCnt >= SERIAL_BUF_RECEPTION)
	{
		s_receptionCnt = 0;
	}
	else
	{
		valueObtained = RXB00;
		
		if(g_p_bufReception == g_bufReception)	
		{
			//valueObtained = RXB00;
			
			if(valueObtained == WAKE_CODE)			//Wake up reception
			{
				s_receptionCnt = 0;  
				
				btReception500msOn = 1;
				
				s_g_transRec500msCnt = 0;				
			}
			
			if(valueObtained == STX)				//Clear RECEPTION buffer.
			{		
				s_receptionCnt++;
						
				ClearReceptionBuf();
				
				*g_p_bufReception++ = valueObtained;
				
				btReception500msOn = 1;
				
				s_g_transRec500msCnt = 0;
			} 		
		}
		else
		{
			if(1 <= s_receptionCnt)
			{
				s_receptionCnt++;
				
			//if((g_bufReception[2]+4)>=s_receptionCnt)
			//{
					*g_p_bufReception++ = valueObtained;
						
					btReception500msOn = 1;
						
					s_g_transRec500msCnt = 0;					
			//}
				
				//0x16,i.e. an end code, is not given to *g_p_bufReception. 			
				if(((g_bufReception[2]+4)==(s_receptionCnt-1))&& 
					 (ETX==valueObtained))
				{
					s_receptionCnt = 0;
					
					g_p_bufReception = g_bufReception;
					
					btReception500msOn = 0;
					
					s_g_transRec500msCnt = 0;
					
					g_btWait20ms = 1;
					
		      RXE00 = 0;                              
		                          
		      SRMK00 = 1;                                              
				}		
			}					
		}			
	}		
}



/*    
** Function name: ErrorRceptionCheck                                                 
**
** Description:
**	       The function is to check each byte of the whole frame received.
**
** Input parameters:
**	            no
**
** Output parameters:
**	             no
**
** Return value:
**	        1: error occurs.
**					0: the reception is correct.		
*/
Uchar ErrorRceptionCheck()
{
	Uchar *p_bufReception = g_bufReception;
	
	Uchar dataLength = *(p_bufReception+2);
	
	Uchar chkSum = 0;
	
	if(STX != *p_bufReception)
	{
		return 1;
	}
	
	p_bufReception++;
	
	while(dataLength-- != 0)
	{
		chkSum += *p_bufReception++;
	}
	
	if(*p_bufReception++ != chkSum)
	{
		return 1;
	}
	
	if(ETX != *p_bufReception)				//ETX -- End of TeXt
	{
		return 1;
	}
	
	return 0;
}
 

/*    
** Function name: CRC_Sum                                                 
**
** Description:
**	       The function is to figure out the value by CRC method.
**                   Consider later!!!!!!! 
**
** Input parameters:
**	            no
**
** Output parameters:
**	             no
**
** Return value:
**	        CRC check sum.		
*/
//Uchar CRC_Sum()    
//{
	
//} 



//void TransmissionEnabled()
//{
	      	
//}


void CommReceptionEnabled()
{           
  RXE00 = 1;	//Receive operation enabled. 
		
	SRMK00 = 0;  //Interrupt Mask Flag for reception interrupt disabled.
	
	TXE00 = 0;	//Transmit operation disabled. 
	
	STMK00 = 1;  //Enable Interrupt Mask Flag for reception interrupt.	
}


/*    
** Function name: ByteLengthSelection                                                  
**
* Description:
**         Return g_byteLength according to different g_controlCode.                                                
**
** Input parameters:
**	            g_controlCode
**
* * Output parameters:
**	            no
**
** Return value:
**	        g_byteLength		
*/

Uchar ByteLengthSelection(Uchar ctrlCode)
{
	Uchar byteLength; 
	
	switch(ctrlCode)
	{
		case 4:									//2.3.4 HSR7217 -> main CPU key value																		
						byteLength = 2;
																														
						break;
						
		case 5:										//2.3.5 HSR7217 -> main CPU code value																	
						byteLength = 5;		//Adopt genuine NEC format
																														
						break;
	
	  				
		case 6:										//2.3.6 HSR7217 -> main CPU ASCII mode																	
						byteLength = 6;		
																														
						break;
		
		
		//	2003-10-30 15:15			
	  case 8:
	  			  byteLength = hanZiByteAmount;	
																														
						break;
		
		
		//The more still exists...	
						
		default:
						
						break;
						
	}
	
	return byteLength;
}


/*    
** Function name: CheckSumTransmit                                                  
**
* Description:
**         The function is to add all the data to be transmitted to  
**         transmission buffer array, i.e. g_bufTransmit[].                                                
**
** Input parameters:
**	            control code.   
**
* * Output parameters:
**	             no
**
** Return value:
**	        check sum that is to be transmitted.		
*/
Uchar CheckSumTransmit(Uchar ctlCde)
{
	Uchar transSum = 0;
	
	Uchar *p_bufTrans = g_bufTransmit;
	
	Uchar transLen = ByteLengthSelection(ctlCde) + 3;
	
	while(transLen-- != 0)
	{
		transSum += *p_bufTrans++;
	}
	
	return transSum;
}


/*    
** Function name: Inter_TM0                                                 
**
** Description:
**	       The function is ISR - Interrupt Service Routine of timer0
**         interval timer and used for UART reception processing. 
**
** Input parameters:
**	            no
**
** Output parameters:
**	             no
**
** Return value:
**	        no		
*/
void Inter_TM0()
{
	if(g_btWait20ms)												//s_g_transRec500msCnt cleared.
	{
		s_g_transRec500msCnt++;
		
		if(s_g_transRec500msCnt >= 10)            //20ms passed.
		{
			g_btWait20ms = 0;
			
			g_btReceptionEnd = 1;               //Reception ends.
		}
  }  
    
  if(btReception500msOn)
  {
  	s_g_transRec500msCnt++;
  	
  	if(s_g_transRec500msCnt >= 200)		//Reception enabled every 400ms.
  	{
  		s_g_transRec500msCnt = 0;
  		
  		btReception500msOn = 0;
  		
  		CommReceptionEnabled();
  		
  		//ReceiveCounter = 0;
  	}
  }               
} 
 
//The buffer for transmission is cleared.
void ClearTransmitBuf()
{
	Uchar j;
	
	for(j = 0; j < SERIAL_BUF_RECEPTION; j++)
	{
		g_bufTransmit[j] = 0;				                                     
	} 
}   

//The buffer for reception is cleared.
void ClearReceptionBuf()
{
	Uchar i;
	
	for(i=0; i++; i<SERIAL_BUF_RECEPTION)
	{
		g_bufReception[i] = 0;
	}
} 

⌨️ 快捷键说明

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