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

📄 uart.c

📁 Taiwan sunplus develop spce3200, it is a test program ----- testboard source code
💻 C
字号:
//=============================================================
//File Name:	UART.c
//Description:	UART send and receive subroutine
//Update:		2007.01.16 V1.0	by wangtao <wangtao@sunnorth.com.cn>
//=============================================================
#include "SPCE3200_Register.h"
#include "SPCE3200_Constant.h"

//=============================================================
// Prototype:		void UART_Initial(int BaudRate);
// Description:		Initialize SPCE3200 UART module
// Arguments:		BaudRate: BaudRate code
// Return Value:	None
//=============================================================
void UART_Initial(int BaudRate)
{
    *P_UART_CLK_CONF = 0x0000;
	*P_UART_CLK_CONF = C_UART_CLK_EN | C_UART_RST_DIS;			// Enable UART clock
    *P_UART_BAUDRATE_SETUP = BaudRate;							// Transmit BaudRate setup information
    
    *P_UART_MODE_CTRL = C_UART_EVEN_PARITY						// Even
                   | C_UART_STOP_1BIT							// Stop bit: 1 bit
                   | C_UART_DATA_8BIT							// Data bits: 8 bits
                   | C_UART_CTRL_EN								// Enable UART function
                   ;
}

//=============================================================
// Prototype:		void UART_SendChar(char cData);
// Description:		Send a character through the UART serial data send port
// Arguments:		Data: The character to be sent
// Return Value:	None
//=============================================================
void UART_SendChar(char cData)
{
    while(*P_UART_TXRX_STATUS & C_UART_TXFIFO_FULL);			// Send FIFO is full?
    *P_UART_TXRX_DATA = cData;
	while(*P_UART_TXRX_STATUS & C_UART_BUSY_FLAG);				// Send OK?
}

//=============================================================
// Prototype:	 	char UART_GetChar();
// Description: 	Receive a character through the UART data receive port.
// Arguments:	 	None
// Return Value: 	The character received
//=============================================================
char UART_GetChar()
{
    char cData = 0;
    int i=0;
    
    while(*P_UART_TXRX_STATUS & C_UART_RXFIFO_EMPTY)			// Receive FIFO empty? wait
    {
    	i++;
    	if(i==100000)break;
    }
    if(i==100000)
    	cData = 0xFF;
    else
    	cData = *P_UART_TXRX_DATA;								// Get the next data
    
    return cData;
}

⌨️ 快捷键说明

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