#include <REGX52.H>
#include "Delay.h"
void Delay(unsigned int xms)
{
unsigned char i, j;
while (xms--)
{
i = 2;
j = 199;
do
{
while (--j);
} while (--i);
}
}
void Uart_Init()
{
SCON = 0x50;//定时器1启动
PCON = 0x80; //SMOD=1 波特率加倍
TMOD &= 0x0f;
TMOD |= 0x20;//8位自动重装
TL1 = 0xFA; //设定定时初值
TH1 = 0xFA; //设定定时器重装值
TR1 = 1; //定时器1启动
ET1 = 0;//禁止定时器T1中断启动
EA = 1;
ES = 1;
}
void Uart_Send(unsigned char Data)
{
SBUF = Data;
while (TI==0)
{
}
TI = 0;
}
unsigned char Sec;
void main()
{
Uart_Init();
while (1)
{
Uart_Send(Sec);
Sec++;
Delay(1000);
}
}
void Ruat_Routine() interrupt 4
{
if (RI==1)
{
P2 = SBUF;
RI = 0;
}
}
51单片机串口通信错误问题和解决方法
最新推荐文章于 2024-09-03 20:58:27 发布