串口发送字符串到串口软件
/*发送函数*/
#include <reg52.h>
#define uchar unsigned char
#define uint unsigned int
uchar Mydata[10]={'q','w','e','r','t','y'};
//sbit KEY=P1^0;
void InitUART(void)
{
TMOD = 0x20; //定时器
SCON = 0x50; //串口
TH1 = 0xF3;
TL1 = TH1;
PCON = 0x80;
EA = 1;
ES = 1;
TR1 = 1;
}
void SendOneByte(uchar Onedata) //发送
{
SBUF = Onedata;
while(TI==0);
TI = 0;
}
void Delay()
{
uint i,j;
for(i=0;i<10;i++)
for(j=0;j<12500;j++);
}
void main(void)
{
uint i;
P2=0xff;
InitUART();
Delay(); //延时一会,让硬件就位,如果不延时,不成功
while(1)
{
for(i=0;i<sizeof(Mydata);i++)
{
P2=0x00;
SendOneByte(Mydata[i]);
}
Delay();
P2=0xff;
Delay();
}
}
//注意,4800波特率
长风破浪会有时,直挂云帆济沧海!
可通过下方链接找到博主
https://www.cnblogs.com/judes/p/10875138.html