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

📄 uart_0.c

📁 ucos on lpc213x ,and a sample for the arm7
💻 C
字号:
// this file is define the UART0 function prototype


#include "uart.h"


void UART0_Init (void)
{
	uint16 Fdiv;
	
	PINSEL0 = (PINSEL0 & (~0x0F)) | 0x05;
	
	U0LCR = 0x83;						/* DLAB=1,允许设置波特率	*/
	Fdiv  = (Fpclk / 16) / UART_BPS_2;	/* 设置波特率				*/
	U0DLM = Fdiv / 256;
	U0DLL = Fdiv % 256;
	U0LCR = 0x03;
}

uint8 UART0_GetByte (void)
{
	uint8 rcv_dat;
	
	while ((U0LSR & 0x01) == 0);
	rcv_dat = U0RBR;
	
	return (rcv_dat);	
}

void UART0_GetStr (uint8 *s, uint32 n)
{
	for ( ; n>0; n--)
	{
		*s++ = UART0_GetByte();
	}
}

void UART0_SendByte (uint8 dat)
{
	U0THR = dat;
	while ((U0LSR & 0x40) == 0);		/* 等待数据发送完毕			*/
}

void UART0_SendStr (char *str)
{
	while (1)
	{
		if (*str == '\0')	break;		/* 遇到结束符,退出			*/
		UART0_SendByte(*str++);			/* 发送数据					*/
	}
}



//-------------------------end file--------------------------------------------------------------------------

⌨️ 快捷键说明

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