#include "uart.h"
#define UTRSTAT0 (*(volatile unsigned int *)0xE2900010)
#define UTXH0 (*(volatile unsigned char *)0xE2900020)
#define URXH0 (*(volatile unsigned char *)0xE2900024)
int getchar(void)
{
int c;
c = (int)uart_get_char();
if (c == '\r')
return '\n';
return c;
}
char *gets(char *s)
{
char *p=s;
while((*p=getchar())!='\n')
{
if(*p!='\b')
putchar(*p++);
else
if(p>s)
{
puts("\b \b");
p--;
}
}
*p='\0';
putchar('\n');
return 0;
}
void putchar_hex(char c)
{
char * hex = "0123456789ABCDEF";
uart_putchar(hex[(c>>4) & 0x0F]);
uart_putchar(hex[(c>>0) & 0x0F]);
return ;
}
int putchar(int c)
{
if(c=='\r')
{
while(!(UTRSTAT0&(1<<1)));
UTXH0='\n';
}
if(c=='\n')
{
while(!(UTRSTAT0&(1<<1)));
UTXH0='\r';
}
while(!(UTRSTAT0&(1<<1)));
UTXH0=c;
}
int puts(const char *s)
{
while(*s)
putchar(*s++);
return 0;
}
void putint_hex(int a)
{
putchar_hex((a>>24)&0xff);
putchar_hex((a>>16)&0xff);
putchar_hex((a>>8)&0xff);
putchar_hex((a>>0)&0xff);
}
移植打印myprinf
最新推荐文章于 2019-02-19 22:00:43 发布