#include "uart.h" __bit busy = 0; /******************************************************************************* * 函 数 名 : uart_init * 函数功能 : 串口通信中断配置函数,通过设置TH和TL即可确定定时时间 * 输 入 : baud:波特率对应的TH、TL装载值 * 输 出 : 无 *******************************************************************************/ void uart_init(u8 baud) { TMOD|=0X20; //设置计数器工作方式2 SCON=0X50; //设置为工作方式1 PCON=0X80; //波特率加倍 TH1=baud; //计数器初始值设置 TL1=baud; ES=1; //打开接收中断 EA=1; //打开总中断 TR1=1; //打开计数器 } void send_string(char *s) { while(*s) { send_data(*s++); } } void send_data(u8 dat) { while(busy); busy = 1; SBUF = dat; } int putchar(char c)//重定向 { send_data(c); return c; }