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

📄 at16c554.c

📁 这是一个C51的有关16c554的驱动源码
💻 C
📖 第 1 页 / 共 2 页
字号:
  //         true:   从缓冲区中成功取得数据
  //         false:  从缓冲区中无法取得数据
  //参  数: *Byte:从缓冲区中取得数据返回
//-----------------------------------------------------------------------------------------------------
/*bool ReadPortRecBuf(uchar Port,Uchar *Byte)
{
if(CommDevice[Port].CommReceive_Trail==CommDevice[Port].CommReceive_Head)  return false;

*Byte=CommDevice[Port].CommReceiveBuffer[CommDevice[Port].CommReceive_Trail];
CommDevice[Port].CommReceive_Trail=(CommDevice[Port].CommReceive_Trail+1)%CommMaxReceiveBuffer;

return true;
}*/
//-----------------------------------------------------------------------------------------------------
  //功  能:往串口发送缓冲区中写数据
  //返回值:
  //         true:   往缓冲区中写数据成功
  //         false:  从缓冲区中写数据失败
  //参  数: Byte:  往缓冲区中写入的数据
//------------------------------------------------------------------------------
bool WritePortSendBuf(uchar Port,Uchar Byte)
{
if((CommDevice[Port].CommSend_Head+1)%CommMaxSendBuffer==CommDevice[Port].CommSend_Trail) return false;

CommDevice[Port].CommSend_Head=(CommDevice[Port].CommSend_Head+1)%CommMaxSendBuffer;
CommDevice[Port].CommSendBuffer[CommDevice[Port].CommSend_Head]=Byte;

return true;
}
//--------------------------------------------------------------------------------
// 外部扩展串行口1中断处理程序(外部中断0)
//--------------------------------------------------------------------------------
void serial1_int() interrupt 0
{
	uchar xdata *ptr;
	uchar event;
	uchar port;
	
	port = 	CHANL1_PORT;
	ptr = 	CommDevice[port].RAMAddress_Map;												// 读ISR 中断状态寄存器
	event = *(ptr+ISR)&0x0f;																// 读最高优先级别的中断码
	_nop_();
	
	switch(event)
		  {
			case EVENT_RXRDY:																// 接受数据到中断
			case EVENT_RXRDY_TIMEOUT:
				for(;*(ptr+LSR)&EVENT_LSR_RECEIVE;)
					{
						CommDevice[port].CommReceiveBuffer[CommDevice[port].CommReceive_Head] = *(ptr+RHR);
						if(((CommDevice[port].CommReceive_Head+1)%CommMaxReceiveBuffer)!=CommDevice[port].CommReceive_Trail)
       						CommDevice[port].CommReceive_Head=(CommDevice[port].CommReceive_Head+1)%CommMaxReceiveBuffer;
					}; //end for
				break;	
		    case EVENT_TXRDY:																//发送数据中断
				if(CommDevice[port].CommSend_Trail!=CommDevice[port].CommSend_Head)			//判断数据包是否发送完毕
			  		{
						for(event=0;(event<FIFO_SIZE)&&(CommDevice[port].CommSend_Trail!=CommDevice[port].CommSend_Head);event++)
				   			{	
    			     			CommDevice[port].CommSend_Trail=(CommDevice[port].CommSend_Trail+1)%CommMaxSendBuffer;
								*(ptr+THR) = CommDevice[port].CommSendBuffer[CommDevice[port].CommSend_Trail];
				   			};//end for
				   		  CommDevice[port].Comm_Stu = SERIAL_STU_BUSY;
			  		}else CommDevice[port].Comm_Stu = SERIAL_STU_FREE;
			 	 break;
		  };//end switch
}
//--------------------------------------------------------------------------------
// 外部扩展串行口2中断处理程序(外部中断2)
//--------------------------------------------------------------------------------
void serial2_int() interrupt 2
{
	uchar xdata *ptr;
	uchar event;
	uchar port;
	
	port = 	CHANL2_PORT;
	ptr = 	CommDevice[port].RAMAddress_Map;												//读ISR 中断状态寄存器
	event = *(ptr+ISR)&0x0f;																//读最高优先级别的中断码
	_nop_();
	
	switch(event)
		  {
			case EVENT_RXRDY:																//接受数据到中断
			case EVENT_RXRDY_TIMEOUT:
				for(;*(ptr+LSR)&EVENT_LSR_RECEIVE;)
					{
						CommDevice[port].CommReceiveBuffer[CommDevice[port].CommReceive_Head] = *(ptr+RHR);
						if(((CommDevice[port].CommReceive_Head+1)%CommMaxReceiveBuffer)!=CommDevice[port].CommReceive_Trail)
       						CommDevice[port].CommReceive_Head=(CommDevice[port].CommReceive_Head+1)%CommMaxReceiveBuffer;
					}; //end for
				break;	
		    case EVENT_TXRDY:																//发送数据中断
				if(CommDevice[port].CommSend_Trail!=CommDevice[port].CommSend_Head)			//判断数据包是否发送完毕
			  		{
						for(event=0;(event<FIFO_SIZE)&&(CommDevice[port].CommSend_Trail!=CommDevice[port].CommSend_Head);event++)
				   			{	
    			     			CommDevice[port].CommSend_Trail=(CommDevice[port].CommSend_Trail+1)%CommMaxSendBuffer;
								*(ptr+THR) = CommDevice[port].CommSendBuffer[CommDevice[port].CommSend_Trail];
				   			};//end for
				   		CommDevice[port].Comm_Stu = SERIAL_STU_BUSY;
			  		}else CommDevice[port].Comm_Stu = SERIAL_STU_FREE;
			 	 break;
		  };//end switch
}

//--------------------------------------------------------------------------------
// 外部扩展串行口3中断处理程序(外部中断6)
//--------------------------------------------------------------------------------
void serial3_int () interrupt 6
{
	uchar xdata *ptr;
	uchar event;
	uchar port;
	
	port = 	CHANL3_PORT;
	ptr = 	CommDevice[port].RAMAddress_Map;											// 读ISR 中断状态寄存器
	event = *(ptr+ISR)&0x0f;															// 读最高优先级别的中断码
	_nop_();
	
	switch(event)
		  {
			case EVENT_RXRDY:															// 接受数据到中断
			case EVENT_RXRDY_TIMEOUT:
				for(;*(ptr+LSR)&EVENT_LSR_RECEIVE;)
					{
						CommDevice[port].CommReceiveBuffer[CommDevice[port].CommReceive_Head] = *(ptr+RHR);
						if(((CommDevice[port].CommReceive_Head+1)%CommMaxReceiveBuffer)!=CommDevice[port].CommReceive_Trail)
       						CommDevice[port].CommReceive_Head=(CommDevice[port].CommReceive_Head+1)%CommMaxReceiveBuffer;
					}; //end for
				break;	
		    case EVENT_TXRDY:															//发送数据中断
				if(CommDevice[port].CommSend_Trail!=CommDevice[port].CommSend_Head)		//判断数据包是否发送完毕
			  		{
						for(event=0;(event<FIFO_SIZE)&&(CommDevice[port].CommSend_Trail!=CommDevice[port].CommSend_Head);event++)
				   			{	
    			     			CommDevice[port].CommSend_Trail=(CommDevice[port].CommSend_Trail+1)%CommMaxSendBuffer;
								*(ptr+THR) = CommDevice[port].CommSendBuffer[CommDevice[port].CommSend_Trail];
				   			};//end for
				   		CommDevice[port].Comm_Stu = SERIAL_STU_BUSY;
			  		}else CommDevice[port].Comm_Stu = SERIAL_STU_FREE;
			 	 break;
		  };//end switch
}
//--------------------------------------------------------------------------------
// 外部扩展串行口4中断处理程序(外部中断7)
//--------------------------------------------------------------------------------
void serial4_int () interrupt 7
{
	uchar xdata *ptr;
	uchar event;
	uchar port;
	
	port = 	CHANL4_PORT;
	ptr = 	CommDevice[port].RAMAddress_Map;											// 读ISR 中断状态寄存器
	event = *(ptr+ISR)&0x0f;															// 读最高优先级别的中断码
	_nop_();
	
	switch(event)
		  {
			case EVENT_RXRDY:																// 接受数据到中断
			case EVENT_RXRDY_TIMEOUT:
				for(;*(ptr+LSR)&EVENT_LSR_RECEIVE;)
					{
						CommDevice[port].CommReceiveBuffer[CommDevice[port].CommReceive_Head] = *(ptr+RHR);
						if(((CommDevice[port].CommReceive_Head+1)%CommMaxReceiveBuffer)!=CommDevice[port].CommReceive_Trail)
       						CommDevice[port].CommReceive_Head=(CommDevice[port].CommReceive_Head+1)%CommMaxReceiveBuffer;
					}; //end for
				break;
		    case EVENT_TXRDY:																//发送数据中断
				if(CommDevice[port].CommSend_Trail!=CommDevice[port].CommSend_Head)		    //判断数据包是否发送完毕
			  		{
						for(event=0;(event<FIFO_SIZE)&&(CommDevice[port].CommSend_Trail!=CommDevice[port].CommSend_Head);event++)
				   			{	
    			     			CommDevice[port].CommSend_Trail=(CommDevice[port].CommSend_Trail+1)%CommMaxSendBuffer;
								*(ptr+THR) = CommDevice[port].CommSendBuffer[CommDevice[port].CommSend_Trail];
				   			};//end for
						CommDevice[port].Comm_Stu = SERIAL_STU_BUSY;
			  		}else CommDevice[port].Comm_Stu = SERIAL_STU_FREE;
			 	 break;
		  };//end switch
}
//--------------------------------------------------------------------------------

⌨️ 快捷键说明

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