51单片机发送一字符串给PC的代码。。。
以下是我写的代码,但没有返回的信息。P0口操作有效求解。。。。
#include <reg51.h>
#define VALUE_A 0x00
#define VALUE_B 0x0ff
sbit kan_led=P3^1;
unsigned char A_return[] = {'S','T','A','R','T','_','A'};
unsigned char B_return[] = {'S','T','A','R','T','_','B'};
unsigned char Other_ret[] = {'E','R','R','O','R','!','!'};
void InisSerial()
{
SCON = 0x50; // 设定串行口工作方式
TMOD = 0x20; // 定时器1工作于8位自动重载模式, 用于产生波特率
TH1 = 0xFD; // 波特率9600
TL1 = 0xFD;
PCON &= 0xef; // 波特率不倍增
TR1 = 1; // 启动定时器1
}
void main()
{
unsigned char temp,count;
InisSerial();
kan_led = 0;
while(1)
{
TI = 0;
SBUF = VALUE_B;
while(!TI);
while(!RI);
RI = 0;
temp = SBUF;
if(temp == VALUE_A)
{
for(count=0;count<6;count++)
{
TI = 0;
SBUF = A_return[count];
while(!TI);
}
P0 = VALUE_A;
}
else if(temp == VALUE_B)
{
for(count=0;count<6;count++)
{
TI = 0;
SBUF = B_return[count];
while(!TI);
}
P0 = VALUE_B;
}
else
{
for(count=0;count<6;count++)
{
TI = 0;
SBUF = Other_ret[count];
while(!TI);
}
}
}
}