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

📄 uart_1.c

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


#include "uart.h"



void UART1_Init (void)
{
	uint16 Fdiv;
	
	PINSEL0 = (PINSEL0 & (~(0x0F<<16))) | (0x05<<16);
	
	U1LCR = 0x83;						/* DLAB=1,允许设置波特率	*/
	Fdiv  = (Fpclk / 16) / UART_BPS_2;	/* 设置波特率				*/
	U1DLM = Fdiv / 256;
	U1DLL = Fdiv % 256;
	U1LCR = 0x03;
}

uint8 UART1_GetByte (void)
{
	uint8 rcv_dat;
	
	while ((U1LSR & 0x01) == 0);
	rcv_dat = U1RBR;
	
	return (rcv_dat);	
}

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

void UART1_SendByte (uint8 dat)
{
	U1THR = dat;
	while ((U1LSR & 0x40) == 0);		/* 等待数据发送完毕			*/
}

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




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

⌨️ 快捷键说明

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