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

📄 main.c

📁 这是LPC2300的例程 ZLG的ARM2300开发板带的
💻 C
字号:
/****************************************Copyright (c)**************************************************
**                               Guangzou ZLG-MCU Development Co.,LTD.
**                                      graduate school
**                                 http://www.zlgmcu.com
**
**--------------File Info-------------------------------------------------------------------------------
** File name:			main.c
** Last modified Date:  2004-09-16
** Last Version:		1.0
** Descriptions:		The main() function example template
**
**------------------------------------------------------------------------------------------------------
** Created by:			Chenmingji
** Created date:		2004-09-16
** Version:				1.0
** Descriptions:		The original version
**
**------------------------------------------------------------------------------------------------------
** Modified by:			Litiantian
** Modified date:		2006-12-30
** Version:
** Descriptions:		UART0通讯实验,查询方式。
**
********************************************************************************************************/
#include 	"config.h"

/*********************************************************************************************************
** 函数名称:UART0_IniDft
** 函数功能:按默认值初始化串口0的引脚和通讯参数。设置为8位数据位,1位停止位,无奇偶校验,波特率115200。
** 入口参数:无 
** 出口参数:无
**********************************************************************************************************/
void UART0_IniDft (void)
{
	uint32 	Fdiv = 0;
	PCONP |= 1 << 3;						// 打开UART0
	/* 初始化相关的IO */
	PINSEL0 = (0x01 << 4) | (0x01 << 6);	// 设置P0.2和P0.3连接到UART0
	/* 初始化串口通讯参数 */
	U0LCR 	= 0x80;							// 设置为8位数据位,1位停止位,无奇偶校验,DLAB=1,允许设置波特率
	Fdiv 	= (Fpclk / 16) / 115200;		// 设置波特率
	U0DLM 	= Fdiv / 256;
	U0DLL 	= Fdiv % 256;
	U0LCR 	= 0x03;							// 令DLAB位为0
	U0FCR 	&= ~0x07;						// 禁用FIFO
    U0IER 	&= ~0x07;						// 禁止UART产生中断
}

/*********************************************************************************************************
** 函数名称:UART0_RcvData
** 功能描述:从串口0接收count个数据到缓存data_buf中
** 入口参数:data_buf:接收数据缓冲区首地址 
**			 count	 :接收字节数
** 出口参数:无
********************************************************************************************************/
void UART0_RcvData(uint8 *data_buf,uint8 count)
{	
	uint8 i;
	for(i = 0;i < count;i++)
	{
		while ((U0LSR & 0x01) == 0);
		data_buf[i] =U0RBR;
	}
}

/*********************************************************************************************************
** 函数名称:UART0_SendStr
** 函数功能:通过串口0发送一个字符串
** 入口参数:str	要发送的字符串的指针
** 出口参数:无
*********************************************************************************************************/
void UART0_SendStr (uint8 const *str)
{
	while (1)
	{
		if (*str == '\0')	break;		// 遇到结束符则退出
		U0LCR 	= 0x03;					// 令DLAB位为0
		U0THR   = *str;
		str++;
		while ( (U0LSR & 0x20) == 0 );	
	}
}

/*********************************************************************************************************
** 函数名称:main
** 函数功能:以查询方式从串口0接收字符串然后发送到上位机显示。
** 入口参数:无
** 出口参数:无
** 调试说明:需要PC串口显示终端软件如EasyARM.exe。
*********************************************************************************************************/
int main (void)
{
	uint8 SndStr[32]; 					// 定义发送和接收缓冲
	uint32 i;
	UART0_IniDft();						// 串口0初始化为波特率115200,帧格式设置为8位数据位,1位停止位,无奇偶校验,且初始化串口引脚
	while (1)
	{
		for(i = 0;i < 32;i++)	SndStr[i] = 0;	// 在接收前,清0缓存
		UART0_RcvData (SndStr,19);				// 接收上位机发来的字符串
		UART0_SendStr(SndStr);					// 向串口发送字符串
	}
    return 0;
}
/*********************************************************************************************************
**                            End Of File
********************************************************************************************************/

⌨️ 快捷键说明

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