51_LanQiaoBei/题目/模拟题/4T14届模拟1_左岚85/4T14届模拟1/Driver/Uart.c
2025-04-13 01:02:19 +08:00

20 lines
534 B
C
Raw Permalink 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"
void Uart1_Init(void) // 9600bps@12MHz
{
SCON = 0x50; // 8位数据,可变波特率
AUXR |= 0x01; // 串口1选择定时器2为波特率发生器
AUXR |= 0x04; // 定时器时钟1T模式
T2L = 0xC7; // 设置定时初始值
T2H = 0xFE; // 设置定时初始值
AUXR |= 0x10; // 定时器2开始计时
ES = 1; // 打开串口中断
EA = 1; // 打开总中断
}
extern char putchar(char ch)
{
SBUF = ch; // 将ch写入SBUF发出数据
while (TI == 0)
; // 等待发送完成
TI = 0; // 清除发送完成标志
return ch;
}