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

📄 2440uart.c

📁 ucosii 移植到ARM 9 2440环境 基本已经完成 没有最终试验 恐有差错
💻 C
字号:
#include "includes.h"
#include "2440lib.h"
#include "2440lcd.h"
#include "2440addr.h"
#include "os_cpu.h"
#include "2440uart.h"
#include "os_cfg.h"
#include <stdarg.h>
#include <stdio.h>

static void Uart_SendByte	(int data);
static void Uart_SendString	(char *pt);

void Uart_Init(int pclk, int baud)
{
 		unsigned int Reg;

		Reg = rGPHCON;
		Reg &=0xFFFFFF0F;
		Reg |=0x000000A0;
		rGPHCON = Reg;		//-- GPH PORT 檬扁拳 FOR TXD0 & RXD0    
    
    rUFCON0 = 0x0;	//UART channel 1 FIFO control register, FIFO disable
    rUMCON0 = 0x0;	//UART chaneel 1 MODEM control register, AFC disable
    rULCON0 = 0x3;  //Line control register : Normal,No parity,1 stop,8 bits
	
    rUCON0	 = 0x245;   // Control register

		Reg = (pclk / (baud * 16)) -1;
		rUBRDIV0 = Reg;

		while(!(rUTRSTAT0 & 0x4));	//Wait until tx shifter is empty.

}


void Uart_Printf(const char *fmt, ...)
{
    va_list	ap;
    char 	string[256];

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


static void Uart_SendByte(int data)
{
	if(data=='\n')
	{
		while(!(rUTRSTAT0 & 0x2))
			;

		rUTXH0 = '\r';
	}
	
	while(!(rUTRSTAT0 & 0x2))	//Wait until THR is empty.
		;   

	rUTXH0 = data;
}  


static void Uart_SendString(char *pt)
{
    while(*pt)
        Uart_SendByte(*pt++);
}

⌨️ 快捷键说明

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