uart_temp/src/uart.c

41 lines
878 B
C
Raw Normal View History

2023-12-29 00:57:13 +08:00
#include "uart.h"
__bit busy = 0;
/*******************************************************************************
* : uart_init
* : TH和TL即可确定定时时间
* : baudTHTL装载值
* :
*******************************************************************************/
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;
}