📄 main.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.c
*功能:向串口发送数据
*说明:使用外部11.0592MHz晶振,根据config.h文件配置,Fpclk=11.0592MHz
* 通信波特率为115200,8位数据位,1位停止位,无奇偶校验位
*********************************************************************/
#include "config.h"
#define uint8 unsigned char
#define uint32 unsigned int
#define UART_BPS 115200 //定义通讯波特率
uint8 const SEND_STRING[]="hello world!\r\n";
/*********************************************************************
*名称:DelayNS(uint32 dly)
*功能:长延时软件
*入口参数:dly 延时参数,值越大,延时越久
*出口参数:无
*********************************************************************/
void DelayNS(uint32 dly)
{
uint32 i;
for(;dly>0;dly--)
{
for(i=0;i<5000;i++);
}
}
/*********************************************************************
*名称:UART0_Init()
*功能:初始化串口0。设置为8位数据位,1位停止位,无奇偶校验位,波特率115200
*入口参数:无
*出口参数:无
*********************************************************************/
void UART0_Init(void)
{
uint16 Fdiv;
U0LCR=0x83; //DLAB=1,可设置波特率
Fdiv=(Fpclk/16)/UART_BPS; //设置波特率
U0DLM=Fdiv/256;
U0DLL=Fdiv%256;
U0LCR=0x03;
}
/*********************************************************************
*名称:UART0_SendByte()
*功能:向串口发送字节数据,并等待发送完毕
*入口参数:data 要发送的数据
*出口参数:无
*********************************************************************/
void UART0_SendByte(uint8 data)
{
U0THR=data; //发送数据
while((U0LSR&0x40)==0); //等待数据发送完毕
}
/*********************************************************************
*名称:UART0_SendStr()
*功能:向串口发送一字符串
*入口参数:str 要发送的字符串的指针
*出口参数:无
*********************************************************************/
void UART0_SendStr(uint8 const *str)
{
while(1)
{
if(*str=='\0') break;
UART0_SendByte(*str++); //发送数据
}
}
/*********************************************************************
*名称:main()
*功能:向串口UART0发送字符串"hello world!"
*********************************************************************/
int main(void)
{
PINSEL0=0x00000005; //设置I/O连接到UART0
UART0_Init();
while(1)
{
UART0_SendStr(SEND_STRING);
DelayNS(10);
}
return(0);
}
/*********************************************************************************************************
** End Of File
********************************************************************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -