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

📄 uart.c

📁 easyarm2103开发板资料
💻 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 & (~0x0F);                                        
    PINSEL0 = PINSEL0 | 0x05; 
     
    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);                                        /*  等待数据发送完毕            */
}

/*********************************************************************************************************
**函数名称:PC_DispChar( )
**函数功能:向PC机发送显示字符
**入口参数:x      显示位置X坐标
**          y      显示位置Y坐标
            char   显示的字符,不能为0xff
            color  显示的颜色
**出口参数:无
********************************************************************************************************/
void PC_DispChar(uint8 x, uint8 y, uint8 chr, uint8 color)
{
    UART0SendByte (0xFF);       //帧头
    UART0SendByte (x);
    UART0SendByte (y);
    UART0SendByte (chr);
    UART0SendByte (color);
}


/*********************************************************************************************************
**函数名称:ISendStr( )
**函数功能:向PC机发送字符串
**入口参数:x      字符串显示起始位置X坐标
**          y      字符串显示起始位置Y坐标
            color  显示的颜色
            *str   要显示的字符串
**出口参数:无
********************************************************************************************************/
void ISendStr(uint8 x, uint8 y, uint8 color, char *str)
{
    while(1)
    {
        if(*str == '\0')  break;
        PC_DispChar(x, y, *str, color);
        x++;
        str++;
        if(x>= 80)
        {
            x= 0;
            y++;   
        }
    }
}

⌨️ 快捷键说明

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