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

📄 uart.c

📁 easyarm 的主要程序
💻 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:			Chen Mingji
** Created date:		2004-09-16
** Version:				1.0
** Descriptions:		The original version
**
**-------------------------------------------------------------------------------------------------------
** Modified by:         Li Baihua
** Modified date:       2008-04-02
** Version:             1.1
** Descriptions:        串口0通信-查询方式实验
**
*********************************************************************************************************/
#include "config.h"
#include "stdio.h"

# define    UART_BPS    9600                                            /*  串口通信波特率              */

/*********************************************************************************************************
** Function name:		UARTInit 
** Descriptions:		串口初始化,设置为8位数据位,1位停止位,无奇偶校验,波特率为9600
** input parameters:    uiDly   值越大,延时时间越长
** output parameters:   无
** Returned value:      无
*********************************************************************************************************/
void UARTInit (void)
{
    uint16 uiFdiv;
    
    PINSEL0 = (PINSEL0 & 0xFFFFFFF0) | 0x00000005;
    
    U0LCR  = 0x83;                                                      /*  允许设置波特率              */
    uiFdiv = (Fpclk / 16) / UART_BPS;                                   /*  设置波特率                  */
    U0DLM  = uiFdiv / 256;
    U0DLL  = uiFdiv % 256; 
    U0LCR  = 0x03;                                                      /*  锁定波特率                  */
}

/*********************************************************************************************************
** Function name:		UART0SendByte
** Descriptions:		向串口发送子节数据,并等待数据发送完成,使用查询方式
** input parameters:    uiDat   要发送的数据
** output parameters:   无
** Returned value:      无
*********************************************************************************************************/
void UART0SendByte (uint8 uiDat)
{
    U0THR = uiDat;                                                      /*  写入数据                    */
    while ((U0LSR & 0x40) == 0);                                        /*  等待数据发送完毕            */
}

/*********************************************************************************************************
** Function name:		PC_DispChar
** Descriptions:		向PC机发送数据,LED数码显示
** input parameters:    uiDat   要发送的数据
** output parameters:   无
** Returned value:      无
*********************************************************************************************************/

/*******************************************************************************************************
** 函数名称 :()
** 函数功能 :。
** 入口参数 :x		显示字符的横坐标
**			  y		显示字符的纵坐标
**			  chr	显示的字符,不能为ff
**			  color	显示的状态,包括前景色、背景色、闪烁位。
**					与DOS字符显示一样:0~3,前景色,4~6,背景色,7,闪烁位。
** 出口参数 :无	
*******************************************************************************************************
*/
void PCDispChar (uint8 uiX, uint8 uiChr)
{
	UART0SendByte(0xFF);	// 起始字符
	UART0SendByte(0x80);
	UART0SendByte(uiX);
	UART0SendByte(uiChr);
	UART0SendByte(0x00);
}

⌨️ 快捷键说明

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