"串口调试助手"是怎样把接收到的字符串转换成十六进制的啊?
能给出代码吗?

解决方案 »

  1.   

    "串口调试助手"上面显示数据应该是字符吧!
    可以自己写呀,串口读上来的数据是unsigned char 类型!
    把它转化成相应的16进制字符就可以了呀!当然要自己写转化的函数了!
    下面代码共你参考一下:
            unsigned chat uchar[20];
            int j=1;
            temp=(int)uchar[j];
            temph=temp/16;
            templ=temp%16;
            if(temph>=0&&temph<10)
               mm[j*2]=temph+0x30;
            else if(temph==10)
               mm[j*2]='A';
            else if(temph==11)
               mm[j*2]='B';
            else if(temph==12)
               mm[j*2]='C';
            else if(temph==13)
               mm[j*2]='D';
            else if(temph==14)
               mm[j*2]='E';
            else if(temph==15)
               mm[j*2]='F';        if(templ>=0&&templ<10)
               mm[j*2+1]=templ+0x30;
            else if(templ==10)
               mm[j*2+1]='A';
            else if(templ==11)
               mm[j*2+1]='B';
            else if(templ==12)
               mm[j*2+1]='C';
            else if(templ==13)
               mm[j*2+1]='D';
            else if(templ==14)
               mm[j*2+1]='E';
            else if(templ==15)
               mm[j*2+1]='F';
    }