www.pudn.com > ARM_RTL8019.rar > uart.c


#define UART_GLOBALS 
#include "config.h" 
#include "cfg_net.h" 
/* 
void DelayNs(uint16 dly) 
{uint16 time=0; 
  while(dly--) 
  	{ 
  	while(time<200)   time++; 
  	} 
} 
*/ 
/********************************************************************** 
**函数原型:    void 	Uart0_Init( uint16 baud) 
**入口参数:?无 
**出口参数:		无 
**返 回 值:	无               
**说    明:	初始化串口 
************************************************************************/ 
void Uart0_Init(uint32 bps) 
{uint16 fdiv; 
PINSEL0=(PINSEL0&0xfffffff0)|05;   //设置管脚为UART0    0101 
 
//====设置波特率=================== 
U0LCR=0x83;//1000  0011   
fdiv=(Fpclk/16)/bps; 
U0DLL=fdiv&0x00ff; 
U0DLM=fdiv>>8        ;  //除数寄存器高位 
//工作方式为8位数据 1bit停止位,无奇偶校验 
U0LCR=0x03;    //0000 0011    
       
//U0FCR= 0x07;//00000111 
} 
 
 
void UartSend( uint8 data) 
{	U0THR = data;			 
	while((U0LSR&0x40)==0);		//等待知道THR变空 
										   	       	 
} 
 
void UartSendStr(uint8 *str) 
{uint8 i,j; 
  while(1) 
    { 
    if(*str==NULL)  break; 
		UartSend(*str++); 
    } 
  for(i=0;i<200;i++) 
	{ 
		for(j=0;j<200;j++); 
	} 
  // DelayNs(10);  
} 
 
/* 
void printf(uint8 *str) 
{   
    UartSendStr(uint8 *str); 
  } 
  */