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

📄 main.c

📁 该程序是基于周立功的magic arm箱上的
💻 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:
** Modified date:
** Version:
** Descriptions:
**
********************************************************************************************************/

/**************************************************************
函数名称:
函数功能:
传递参数:
返回参数:
***************************************************************/


/**************************************************************
函数名称:main()
函数功能:
传递参数
返回参数:
说明:使用外部11.0592MHz,根据CONFIG文件配置,Fpclk=11.0592MHz
        波特率为115200,8位数据,1为停止位,无奇偶校验
***************************************************************/


#include "config.h"
#define  UART_BPS  115200//定义波特率
uint8   SEND_STRING[]="Hello World!\r\n";
uint8 buffer,buff[10]={0};
   
   
/**************************************************************
函数名称:Delay()
函数功能:延时
传递参数:uint32
返回参数:无
***************************************************************/
void  Delay(uint32 dy)
{uint32 i;
 while(dy--)
 {i=5000;
  while(i--);
  }
}   

/**************************************************************
函数名称:UART0_Init()
函数功能:初始化串口0,设置为8数据,1位停止位,无奇偶校验,波特率115200
传递参数:无
返回参数:无
***************************************************************/
void  UART0_Init()
{uint16 Fdiv;
 U0LCR=0X83;    //使能访问除数锁存器寄存器,8位数据,1位停止,无奇偶校验
 Fdiv=(Fpclk/16)/UART_BPS;
 U0DLM=Fdiv/256;
 U0DLL=Fdiv%256;
 U0LCR=0X3;// 使能接收发送寄存器
}

/**************************************************************
函数名称:UART0_SendByte()
函数功能:向串口发送字节数据,并等待发送完毕
传递参数:uint8 data,要发送的数据
返回参数:无
***************************************************************/
void UART0_SendByte(uint8 data)
{U0THR=data; //发送数据
 while((U0LSR&0x40)==0);//等待数据发送完毕
}

/**************************************************************
函数名称:UART0_RcvByte()
函数功能:从串口接收字节数据,使用查询方式
传递参数:无
返回参数:uint8 rec_data
***************************************************************/
uint8 UART0_Rec_Byte(void)
{uint8 rec_data;
 while((U0LSR&0X01)==0)
 rec_data=U0RBR;
 U0FCR=0x03;//复位Rx FIFO,同时使能对Rx Tx的访问
 return rec_data;
}

/**************************************************************
函数名称:void UART0_SendStr()
函数功能:向串口发送一字符串
传递参数:uint8 *str
返回参数:无
***************************************************************/
void  UART0_SendStr(uint8 *str)
{
 while(*str!='\0')
 {UART0_SendByte(*str);
  str++;
 }
}


/**************************************************************

***************************************************************/
   
        int main (void)
{ uint8 i;
 
  PINSEL0=0x5;//设置 p00,P01,为串口
  UART0_Init();  
 
  UART0_SendStr(SEND_STRING);
  UART0_SendStr(SEND_STRING);
/*  
 for(i=0;i<10;i++)
   {buffer=UART0_Rec_Byte();
    buff[i]=buffer;
    Delay(1);
    UART0_SendByte(buff[i]);
    Delay(1);

   }
   
   UART0_SendStr(SEND_STRING);*/
   
   while(1)
   {buffer=UART0_Rec_Byte();
    UART0_SendByte(buffer);
   }
  // while(1);
    return 0;
}
/*********************************************************************************************************
**                            End Of File
********************************************************************************************************/

⌨️ 快捷键说明

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