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

📄 uart.c.svn-base

📁 realtek的8186芯片ADSL路由AP源代码
💻 SVN-BASE
字号:
/*#include "loader.h"*/
#include "board.h"
#include "uart.h"


void initUart(unsigned int baud_rate)
{
#ifndef UART_NOT_CONNECTED
    unsigned short divisor;

    /* DLAB Set, 8 bit word, no parity, 1 stop bit */
    *((char *)UART_LCR) = 0x83;

    /* Set Baud Rate to 9600 bps */
    divisor = (CLOCKGEN_FREQ / ( 16 * baud_rate )) - 1;
    *((char *)UART_DLM) = (divisor >> 8) & 0x00FF;
    *((char *)UART_DLL) = divisor & 0x00FF;

    /* Clear DLAB Bit */
    *((char *)UART_LCR) = 0x03;
    
    *((char *)UART_MCR) = 0x00;
#endif
}

void putc( char c )
{
#ifndef UART_NOT_CONNECTED
	if(c=='\n')
		putc('\r');
    /* While !THRE, loop */
    while ( 0 == (*((volatile char *)UART_LSR) & 0x20) );

    *((char *)UART_THR) = c;


#endif
}

void puts( char *string )
{
#ifndef UART_NOT_CONNECTED
    int index = 0;

    while ( 0 != string[ index ] )
    {
		putc( string[ index++ ] );
    }
    return;
#endif
}

void puthex(unsigned long hex)
{
int	i;
char	c;

	for (i=0;i<8;i++)
	{
		c = hex >> 28;
		c += '0';
		if (c > '9')
			c += ('A' - '9' - 1);
		putc(c);
		hex <<= 4;
	}
}


char getc( void )
{
#ifndef UART_NOT_CONNECTED
    if ( 1 == (*((volatile char *)UART_LSR) & 0x01) )
    {
		return *((volatile char *)UART_RBR);
    }
    else
#endif
    {
		return 0;
    }
}

char pollcc( void )
{
    return (*((volatile char *)UART_LSR) & 0x01 );
}

char getcc( void )
{
	while ( 1 != (*((volatile char *)UART_LSR) & 0x01) );
	return *((volatile char *)UART_RBR);
}

⌨️ 快捷键说明

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