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

📄 myuart.c

📁 博创科技arm3000开发板(arm7 44b0) 大量实验源代码 bootloader实验 ucos的移植 ucos的开发柜架 音频实验 电机控制 绘图的API函数 UDP通讯实
💻 C
字号:
#include <stdarg.h>
#include "def.h"
#include "44b.h"
void Uart_SendByte(int Uartnum, U8 data)//ok eric rong
{
	if(Uartnum==0)
    {
		while(!(rUTRSTAT0 & 0x2)); //Wait until THR is empty.
		Delay(1);
		WrUTXH0(data);
   	}
	else
    {
		while(!(rUTRSTAT1 & 0x2));  //Wait until THR is empty.
		Delay(1);
		WrUTXH1(data);
    }	
}		
void Uart_Init(int Uartnum, int mclk,int baud)
{
	int i;
	
	if(mclk==0)
		mclk=MCLK;
	
	if(Uartnum==0){//UART0
		rUFCON0=0x0;     //FIFO disable
		rUMCON0=0x0;
		
		//UART0
		rULCON0=0x3;     //Normal,No parity,1 stop,8 bit
		rUCON0=0x245;    //rx=edge,tx=level,disable timeout int.,enable rx error int.,normal,interrupt or polling
		rUBRDIV0=( (int)(mclk/16./baud + 0.5) -1 );
	}
	else{
		rUFCON1=0x0;
		rUMCON1=0x0;
		//UART1
		rULCON1=0x3;
		rUCON1=0x245;
		rUBRDIV1=( (int)(mclk/16./baud + 0.5) -1 );
	}
    for(i=0;i<100;i++);

}
void Uart_SendString(int Uartnum, char *pt)
{
	while(*pt){
		if(*pt=='\n'){
			Uart_SendByte(Uartnum, '\r');
			Uart_SendByte(Uartnum, *pt++);
		}
		else
			Uart_SendByte(Uartnum, *pt++);
	}
}


//if you don't use vsprintf(), the code size is reduced very much.
void Uart_Printf(char *fmt,...)
{
    va_list ap;
    char string[256];

    va_start(ap,fmt);
    vsprintf(string,fmt,ap);
    Uart_SendString(0, string);
    va_end(ap);
}

void Uart_TxEmpty(int Uartnum)
{
	if(Uartnum==0)
		while(!(rUTRSTAT0 & 0x4)); //wait until tx shifter is empty.
	else
		while(!(rUTRSTAT1 & 0x4)); //wait until tx shifter is empty.
}

char Uart_Getch(char* Revdata, int Uartnum, int timeout)
{
	if(Uartnum==0){
		while(!(rUTRSTAT0 & 0x1)); //Receive data read
		*Revdata=RdURXH0();
		return TRUE;
	}
	else{
		while(!(rUTRSTAT1 & 0x1));//Receive data read
		*Revdata=RdURXH1();
		return TRUE;
	}
}

⌨️ 快捷键说明

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