?? main.c
字號:
/*******************************************************************************
*File: main.C
*功能: 串口發送數據
*說明: 使用外部晶振,不使用PLL,Fpclk=Fcclk/4
*******************************************************************************/
#include "config.h"
/*******************************************************************************
*名稱: DelayNS()
*功能: 長軟件延時
*******************************************************************************/
void DelayNS(uint32 dly)
{ uint32 i;
for(;dly>0;dly--)
for(i=0;i<50000;i++);
}
/*******************************************************************************
*名稱: UART0_Ini()
*功能: 初始化串口0.設置為8位數據位,1位停止位,無奇偶校驗,波特率為9600
*******************************************************************************/
void UART0_Ini(void)
{ U0LCR=0x83; //DLAB=1,可設置波特率
U0DLL=0x12;
U0DLM=0x00;
U0LCR=0x03;
}
/*******************************************************************************
*名稱: UART0_SendByte()
*功能: 向串口發送字節數據,并等待發送完畢
*******************************************************************************/
void UART0_SendByte(uint8 data)
{ U0THR=data; //發送數據
while((U0LSR&0x40)==0); //等待數據發送完畢
{
uint32 i;
for(i=0; i<5; i++);
}
}
/*******************************************************************************
*名稱:UART0_SendStr()
*功能:向串口發送一字符串
*******************************************************************************/
void UART0_SendStr(uint8 const *str)
{ while(1)
{ if(*str=='\0')
{UART0_SendByte('\r');
UART0_SendByte('\n');
break;
}
UART0_SendByte(*str++); //發送數據
}
}
char UART0_RecvByte(void)
{ while(!(U0LSR&0x01));
return U0RBR;
}
/*******************************************************************************
*名稱: main()
*功能: 向串口UART0發送字符串"Hello World!"
*******************************************************************************/
int main(void)
{ uint8 const SEND_STRING[]="HELLO WORLD!\n";
PINSEL0=0x00000005; //設置I/O連接到UART0
PINSEL1=0x00000000;
UART0_Ini();
UART0_SendStr(SEND_STRING);
DelayNS(10);
while(1)
{
UART0_SendByte(UART0_RecvByte());
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -