uart_temp/src/uart.c
2023-12-29 00:57:13 +08:00

41 lines
878 B
C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#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;
}