单片机每隔1s向PC传输一次“aaaaa",用C语言怎么实现,求程序及注解。哪位大神帮帮忙~
1个回答
展开全部
#include <reg52.h>
#define uint unsigned int
#define uchar unsigned char
void Delay(uint x)
{
uchar i;
while(x--)
{
for(i=0;i<120;i++);
}
}
void putc_to_SerialPort(uchar c)
{
SBUF = c;
while(TI == 0);
TI = 0;
}
void puts_to_SerialPort(uchar *s)
{
while(*s != '\0')
{
putc_to_SerialPort(*s);
s++;
Delay(5);
}
}
void main()
{
uchar c = 0;
SCON = 0x40;
TMOD = 0x20;
PCON = 0x00;
TH1 = 0xfd;
TL1 = 0xfd;
TI = 0;
TR1 = 1;
Delay(200);
while(1)
{
puts_to_SerialPort("aaaaa\r\n");
Delay(1000);
}
}
#define uint unsigned int
#define uchar unsigned char
void Delay(uint x)
{
uchar i;
while(x--)
{
for(i=0;i<120;i++);
}
}
void putc_to_SerialPort(uchar c)
{
SBUF = c;
while(TI == 0);
TI = 0;
}
void puts_to_SerialPort(uchar *s)
{
while(*s != '\0')
{
putc_to_SerialPort(*s);
s++;
Delay(5);
}
}
void main()
{
uchar c = 0;
SCON = 0x40;
TMOD = 0x20;
PCON = 0x00;
TH1 = 0xfd;
TL1 = 0xfd;
TI = 0;
TR1 = 1;
Delay(200);
while(1)
{
puts_to_SerialPort("aaaaa\r\n");
Delay(1000);
}
}
追问
请问在上述情况下,如果pc向单片机发送‘T’时单片机开始发送aaaaa,发送‘F’时单片机结束发送aaaaa,该怎么编呢?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询