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

📄 uart.c

📁 凌阳61单片机做的酒精控制器源码 凌阳61单片机做的酒精控制器源码 凌阳61单片机做的酒精控制器源码 凌阳61单片机做的酒精控制器源码
💻 C
字号:
#include"SPCE061A.H"
#include"Uart.h"

typedef struct _UartBufRx{
	unsigned int unRxData[RXBUFSIZE];
	unsigned char ucRxCount;
}UART_BUF_RX_s;
typedef struct _UartBufTx{
	unsigned int unTxData[TXBUFSIZE];
	unsigned char ucTxCount;
}UART_BUF_TX_s;

static UART_BUF_RX_s stRxData;
static UART_BUF_TX_s stTxData;

/******************************************************************
*初始化串口,中断形式
*******************************************************************/
void vUartSysInit(void){
	unsigned int temp;
	temp = *Port_IOB_Dir;
	temp &= 0xfc7f;
	temp |= 0x0040;
	*Port_IOB_Dir |= temp;
	*Port_IOB_Attrib |= 0x0600;
	*Port_UART_Command1 = 0x20;
	*Port_UART_Command2 = 0x00;
	*Port_UART_BaudScalarL = UART_RATE_L;
	*Port_UART_BaudScalarH = UART_RATE_H;
	*Port_UART_Command1 = 0x80;
	*Port_UART_Command2 = 0x80;	
	stRxData.ucRxCount = 0x00;
	stTxData.ucTxCount = TXCOUNT;
}
/******************************************************************
*读取串口数据寄存器的数据 
********************************************************************/  
unsigned int* unUartRx(void){
	if(RXCOUNT <= stRxData.ucRxCount){
		return stRxData.unRxData;
	}else{
		return NULL;
	}
}
/********************************************************************
*向串口数据寄存器写数据 
********************************************************************/ 
void vUartTx(unsigned int* unData){
	unsigned char temp;
	for(temp = 0; temp <TXBUFSIZE; temp++){
		stTxData.unTxData[temp] = unData[temp];
	}
	stTxData.ucTxCount = TXCOUNT;
	*Port_UART_Command1 |= 0x0060;
} 

void UART(void)__attribute__((ISR)){
	unsigned int temp1,temp2;
	temp1 = *Port_UART_Command2;
	if(temp1&0x80){
		if(RXCOUNT > stRxData.ucRxCount){
			stRxData.unRxData[stRxData.ucRxCount] = *Port_UART_Data;
			stRxData.ucRxCount++;
		}else{			
			temp2 = *Port_UART_Data;
		}
	}
	if(temp1&0x60){
		if(TXCOUNT > stTxData.ucTxCount){
			*Port_UART_Data = stTxData.unTxData[stTxData.ucTxCount];
			stTxData.ucTxCount--;
			if(0x00 >= stTxData.ucTxCount){
				*Port_UART_Command1 &= 0xffbf; /*禁止发送中断*/ 
			}
		}
	}
}




⌨️ 快捷键说明

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