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

📄 console.c

📁 s3c2410的烧片程序,用ads编译,可以通过串口或者jtag口烧写
💻 C
字号:
#include <stdarg.h>


#include "DataType.h"
#include "console.h"

#define rULCON0 (*(volatile unsigned *)0x50000000)
#define rUCON0 (*(volatile unsigned *)0x50000004)
#define rUFCON0 (*(volatile unsigned *)0x50000008)
#define rUMCON0 (*(volatile unsigned *)0x5000000C)
#define rUTRSTAT0 (*(volatile unsigned *)0x50000010)
#define rUTXH0 (*(volatile unsigned *)0x50000020)
#define rURXH0 (*(volatile unsigned *)0x50000024)
#define rUBRDIV0 (*(volatile unsigned *)0x50000028)

#define WrUTXH0(ch)	(*(volatile unsigned char *)0x50000020)=(unsigned char)(ch)
extern unsigned int MCLK;

static void Delay(int time)
{
	while(time--);
}

void UartInit(int ch, int baud)
{
	U8 a;
	
	if(!ch)
	{
		rUFCON0 = 0x0;     //禁止使用FIFO
    	rUMCON0 = 0x0;
    	rULCON0 = 0x3;     //正常无奇偶校验,一个停止位,8个数据位
    	rUCON0 = 0x05;    //TX RX 都用PULSE非LEVEL中断   
   
	    //rx=edge,tx=level,disable timeout int.,enable rx error int.,normal,interrupt or polling
	    rUBRDIV0 = (int)(MCLK/(16.0*baud)+0.5)-1;	   
	    //rUBRDIV0 = 32;	 
	    a = rURXH0;
	}

}

void UartSend(int ch, char data)
{
	if(!ch)
	{
		if(data=='\n')
		{
			while(!(rUTRSTAT0&0x2));			
										//改动延时时间1--10
			Delay(10);					//由于超级终端反应较慢,有一个微小延迟
			WrUTXH0('\r');
		}
	
	else									//改动延时时间1--10
		{
			while(!(rUTRSTAT0&0x2));			
										//改动延时时间1--10
			Delay(10);					//由于超级终端反应较慢,有一个微小延迟
			rUTXH0 = data;
		}
			while(!(rUTRSTAT0&0x2));		//等待知道THR变空
   	}

}

int UartReceive(int ch)
{
	if(!ch)
    {	    
		while(!(rUTRSTAT0&0x1));		//等待直到接受到一个数据
		return rURXH0;
    }

}

int UartRxStat(int ch)
{
	if(!ch)    	    
		return (rUTRSTAT0&0x1);    
	    
}

int UartGetch(int ch)
{
	 if(!ch)
    {	    
		if(rUTRSTAT0&0x1)		//如果收到字符就返回该字符
    	    return rURXH0;
		else
			return -1;			//如果没有收到字符就返回0
    }


}

int UartGetkey(int ch)
{
	return rURXH0; 
}

void UartSendString(int ch, char *pt)
{
    while(*pt)
		UartSend(ch, *pt++);
}

/************************************************/
void console_init(int baud)
{
	UartInit(CONSOLE_UART, baud);
}

void putch(char data)
{
	UartSend(CONSOLE_UART, data);
}

void puts(char *str)
{
	while(*str)
		UartSend(CONSOLE_UART, *str++);
}

int getch()
{
	return UartReceive(CONSOLE_UART);
}

int getkey()
{
	return UartGetkey(CONSOLE_UART);
}

int kbhit()
{
	return UartRxStat(CONSOLE_UART);
}


#ifdef	__SDT_COMPILER
typedef char *__va_list[1];

#else
typedef int *__va_list[1];
#endif

int vsprintf(char * /*s*/, const char * /*format*/, __va_list /*arg*/);

void printf(char *fmt, ...)
{
	va_list ap;
    char string[256];    

    va_start(ap, fmt);
    vsprintf(string, fmt, ap);
    UartSendString(CONSOLE_UART, string);
    va_end(ap);
}		

⌨️ 快捷键说明

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