首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

串口输出乱码怎么处理

2013-01-07 
串口输出乱码怎么办?#includereg52.h#includestdio.h#define uint unsigned int#define uchar unsigne

串口输出乱码怎么办?
串口输出乱码怎么处理
#include<reg52.h>
#include<stdio.h>
#define uint unsigned int
#define uchar unsigned char
uchar ch[8];
sbit K1=P3^2;
void delayms(uint x)
{
  while(x--)
  {
    uint i;
    for(i=112;i>0;i--);
{;}
  }
}
void uart(void)
{
 SCON=0x40;
 REN=1;
 PCON=0;
 TMOD=0x20;
 TH1=0xfd;
 TL1=0xfd;
 TI=1;
 TR1=1;
}
int main()
{
  uchar ch[8];
  uint j;
  uart();
  printf("please input the char and input ' 'to stop\n");
  for(j=0;j<8;j++)
   {
     scanf("%c",&ch[j]);
 if(ch[j]==' ')
 break;
   }
  printf("\n");
  printf("please press the K1 to display the word!\n");
   while(K1!=0);
   delayms(100);
    if(K1==0)
    {
      while(K1==0);
  printf("the char is {");
    for(j=0;j<8;j++)
    {
      printf("%c",ch[j]);
        }
  printf("}\n\n\n");
    }
}
请各位帮忙看一下为什么会出现乱码?
[解决办法]
或许是波特率的问题
[解决办法]
串口设置都还正确?
包括波特率,数据位数,停止位数,奇偶校验,流控等等。
还有就是接线/接口什么的还好,有没有接触不良什么的。

[解决办法]
首先排除硬件问题,其次是串口参数设置,最后是使用的串口调试工具.

热点排行