单片机串口通信传输显示乱码
时间:10-02
整理:3721RD
点击:
用proteus仿真,实现单片机向PC端单方向数据传输,在串口调试助手显示。现在显示出来的数据都是乱码,一般这种都是什么原因吗?程序?还是波特率?或者其他?目前的程序是这样的:
#include<reg51.h>
void initSer();
uchar sendFlag = 0;
uchar receFlag =0;
code uchar SHUOMING0[] = "****************************\r\n";
code uchar SHUOMING1[] = "哈哈哈哈";
code uchar SHUOMING2[] = "哈哈哈哈";
code uchar SHUOMING3[] = "****************************\r\n\r\n";
void sendChar(uchar sendValue);
void sendAll(uchar *pValue);
void serInt() interrupt 4
{
if(RI)
{
RI = 0;
receFlag=1;
}
if(TI)
{
TI = 0;
sendFlag = 0;
}
}
void sendChar(uchar Value)
{
SBUF = Value;
sendFlag = 1;
while(sendFlag);
}
void sendAll(uchar *pValue)
{
while((*pValue) != '\0')
{
sendChar(*pValue);
pValue++;
}
}
void initSer()
{
SCON=0X50;
TMOD=0X20;
PCON=0X80;
TH1=0XF3;
TL1=0XF3;
ES=1;
EA=1;
TR1=1;
}
void main()
{
initSer();
while(1)
{
while(receFlag)
{
sendAll(SHUOMING0);
sendAll(SHUOMING1);
sendAll(SHUOMING2);
sendAll(SHUOMING3);
receFlag=0;
}
}
#include<reg51.h>
void initSer();
uchar sendFlag = 0;
uchar receFlag =0;
code uchar SHUOMING0[] = "****************************\r\n";
code uchar SHUOMING1[] = "哈哈哈哈";
code uchar SHUOMING2[] = "哈哈哈哈";
code uchar SHUOMING3[] = "****************************\r\n\r\n";
void sendChar(uchar sendValue);
void sendAll(uchar *pValue);
void serInt() interrupt 4
{
if(RI)
{
RI = 0;
receFlag=1;
}
if(TI)
{
TI = 0;
sendFlag = 0;
}
}
void sendChar(uchar Value)
{
SBUF = Value;
sendFlag = 1;
while(sendFlag);
}
void sendAll(uchar *pValue)
{
while((*pValue) != '\0')
{
sendChar(*pValue);
pValue++;
}
}
void initSer()
{
SCON=0X50;
TMOD=0X20;
PCON=0X80;
TH1=0XF3;
TL1=0XF3;
ES=1;
EA=1;
TR1=1;
}
void main()
{
initSer();
while(1)
{
while(receFlag)
{
sendAll(SHUOMING0);
sendAll(SHUOMING1);
sendAll(SHUOMING2);
sendAll(SHUOMING3);
receFlag=0;
}
}
换换波特率吧
都尝试过了。现在是可以PC向单片机虚拟终端发数据,但单片机向PC串口调试助手发就会乱码。