www.pudn.com > zhiyonglou311.rar > Serial.c


//----------------------------------------------------------------------------- 
// Net SERIAL.C 
// 
// This module handles RS-232 messages and associated tasks 
//----------------------------------------------------------------------------- 
#include "C8051f.h" 
#include "intrins.h" 
#include "net.h" 
#include "serial.h" 
 
bit CommRecDataOverflowFlag,FlagRecComm,SendItComm; 
 
unsigned char CommSendBufferHead, CommSendBufferTail; 
unsigned char CommRecBufferHead, CommRecBufferTail; 
 
unsigned char xdata CommSendBuffer[DB_SENDMAXSIZE] _at_ 0 ; //串行口缓冲区定位在内部4K XRAM中 
unsigned char xdata CommRecBuffer[DB_RECMAXSIZE] _at_ DB_SENDMAXSIZE;  
  
void ClearCommRecBuffer(void) 
{ 
	unsigned char i; 
	CommRecBufferHead=CommRecBufferTail=0; 
	CommSendBufferHead=CommSendBufferTail=0; 
	FlagRecComm=0; 
	for (i=0;i>4; 
	SendCommChar(hex[ch]); 
	ch=senddata&0x0F; 
	SendCommChar(hex[ch]); 
} 
void SendCommWord(unsigned int asciiword) 
//向串口发送一个int型的 hex码表示的字符 例如:asciiword=0x124D 将向串口发送4个字符:'1','2','4','D' 
{ 
	unsigned char ascii; 
	ascii=asciiword>>8; 
	SendCommHex(ascii); 
	ascii=asciiword&0xff; 
	SendCommHex(ascii); 
} 
 
void SendCommLong(unsigned long asciilong) 
{ 
	SendCommWord(asciilong>>16); 
	SendCommWord(asciilong&0xffff); 
} 
*/ 
void serial_send(unsigned char *base) 
{ 
	SendCommString(base); 
} 
 
void SendCommString(unsigned char *base)  
{ 
unsigned char i=0; 
	if (base[0]==0) return; 
	for (;;) 
	{	 
		if (base[i]==0) break; 
		CommSendBuffer[CommSendBufferTail]=base[i];  
		CommSendBufferTail++;  
		if (CommSendBufferTail==DB_SENDMAXSIZE) 
		{ 						 
			CommSendBufferTail=0; 
		} 
		i++; 
	} 
	if (SendItComm) 
	{	 						 
		SendItComm=0; 
		SBUF0=CommSendBuffer[CommSendBufferHead]; 
	} 
	while (CommSendBufferHead!=CommSendBufferTail); 
} 
/* 
void SendCommBuffer(unsigned char *base, unsigned char size)  
{ 
unsigned char i=0; 
	if (!size) { return; }	 
	while (i 0x39) i += 7; 
		*--ptr = i; 
      value = value / radix; 
  	} while(value != 0); 
 
	// Next, move the string 6 places to the left 
	// Include NULL character 
	for( ; (*buf++ = *ptr++); );	 
	return(temphold); 
}