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

📄 uart.c

📁 本文介绍了如何用AD识别用户输入的键盘的方法
💻 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)
{
    
                     //  uiDat="a";

                                                             // uiDat=0x56; //v 的ASCLL        
    U0THR = uiDat;  
    
                           // U0THR="1";
                                                        /*  写入数据                    */
    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 (0x31);
  
     chr=chr;  //一个字节的内容
  
   // UART0SendByte (2);
   
    UART0SendByte (color);
}


/*********************************************************************************************************
**函数名称:ISendStr( )
**函数功能:向PC机发送字符串
**入口参数:x      字符串显示起始位置X坐标
**          y      字符串显示起始位置Y坐标
            color  显示的颜色
            *str   要显示的字符串
**出口参数:无
********************************************************************************************************/
//void ISendStr(uint8 x, uint8 y, uint8 color, char *str)

/*


 void ISendStr( char *str)   //uint8 x, uint8 y, uint8 color,

{
    while(1)
    
    {
    
    
    
    
      if(*str==0xf) break;     //inSeqence[4]
    
      //  if(*str == '\0')  break;   //回车 退出来
        
                                               //       PC_DispChar(8, 8, *str, color);
                                               
      PC_DispChar(8, 8, 4,0x30 );
     
     
       //   x++;
        
        str++;
        
    //    if(x>= 80)
        
        //    {
       //          x= 0;
      //          y++;   
     //   }
        
                                  }

    
    
    
    
                 }   */                  

/*********************************************************************************************************
**函数名称:ISendStr( )
**函数功能:向PC机发送字符串
**入口参数:x      字符串显示起始位置X坐标
**          y      字符串显示起始位置Y坐标
            color  显示的颜色
            *str   要显示的字符串
**出口参数:无
********************************************************************************************************/

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


{
uint8 uiDat;


    while(1)
    {
    
    
    // '\0'  就是0X00 
     
     
     //   if(*str == '\0')  { 
     
     //  数字0的ASCCLL值不等于0  只有"",或'',才是,0x00   数据类型不匹配
        
      if(*str == 0)  { 
        
    uiDat=0x56; //v 的ASCLL  
          
    U0THR = uiDat;  
    
                           // U0THR="1";
                                                        /*  写入数据                    */
    while ((U0LSR & 0x40) == 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 + -