移植打印myprinf

来源:互联网 发布:机锋市场 淘宝 编辑:程序博客网 时间:2024/06/15 03:01
#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++);elseif(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);}

原创粉丝点击