keil下LPC2138实现printf

小小API

我的KEIL实现PRINTF,为了这个小小的目标,我测试实现了底层的功能,因为没有使用半主机功能,#pragmaimport(__use_no_semihosting)所以printf要重新实现,依赖的函数包括ferror(),fputc(), __stdout

都知道虽然printf只是一个简单的功能,但调用时因为是流的输入输出,在全主机和半主机模式下的支持是不同的,半主机是嵌入模式的配置,全主机是开发环境优化配置,能够使用电脑的IO进行仿真处理,配置getch,和文件系统

Serial中的配置

int sendchar (int ch) { /* Write character to Serial Port */
if (ch == '\n') {
while (!(U1LSR & 0x20));
U1THR = CR; /* output CR */
}
while (!(UxLSR & 0x20));

return (UxTHR = ch);
}


int getkey (void) { /* Read character from Serial Port */

while (!(UxLSR & 0x01));

return (UxRBR);
}


/* Implementation of putchar (also used by printf function to output data) */
int sendchar (int ch) { /* Write character to Serial Port */
if (ch == '\n') {
while (!(U1LSR & 0x20));
U1THR = CR; /* output CR */
}
while (!(UxLSR & 0x20));

return (UxTHR = ch);
}


int getkey (void) { /* Read character from Serial Port */

while (!(UxLSR & 0x01));

return (UxRBR);
}


#define UART0这里要 注意


模板的下载地址

http://download.csdn.net/detail/pipixiong999/3096501

转载请注明出处


 

 

你可能感兴趣的:(keil下LPC2138实现printf)