用protues
仿真单片机串口通讯,单片机发送一串字符到串口调试助手,但是第一个字符总是要发送两次,后面就正常了,下面是代码和仿真效果:
#include<AT89X52.h>
#define uchar unsigned char
#define uint unsigned int
sfr p2=0xa0;
sbit led=p2^0;
void iart(void)
{
TMOD=0x20;
SCON=0X50;
TH1=0XFD;
TL1=TH1;
PCON=0X00;
EA=1;
ES=1;
TR1=1;
}
void send(uchar x)
{
SBUF=x;
while(
ti==0);
TI=0;
}
void delay(uint ms)
{
uint i,j;
for(i=0;i<ms;i++)
for(j=0;j<1141;j++);
}
main()
{ uchar i;
uchar str[]="I LOVE YOU!
";
iart();
while(1)
{ i=0;
while(str[i]!=' ')
{
delay(50);
send(str[i]);
led=~led;
i++;
}
}
}
仿真效果为:
-
仿真效果
-
串口调试助手显示
一周热门 更多>