关于串口的字符串输出和二进制数据流输出

串口输出的类型主要分为单字节 字符串和二进制数据流,它们的控制输出函数各不相同。

Windows系统里面,每行结尾是“ <回车><换 行>”,即“ ”

#define CR 0x0d     // 回车13=' '
#define LF 0x0a   // 换行newline =10=' '
#define BLK   0X20  //空格= 32=' '

#define END  0  //空格= 0=' '

一 字符输出:

#include <intrins.h>
void PrintByte(unsigned char byte_data)
{
  while( BUSY == 1 ){
  }
  PRINTER_DATA = byte_data;
  nSTB = 0;
  _nop_(); // 调整 nSTB 信号脉宽
  nSTB = 1;
}

二字符串输出:

void PrintString(char* str)
{
  //while( *str!= 0 )

  //while( *str!= ' ')

  while( *str )//以上都可以,即只要不是结束符

  {
    PrintByte( *(str++));、//注意括号与++
  }
}

打印举例

PrintString("北京炜煌 WH");
PrintByte(CR);

三进制数据流:因数据范围为0x00~0xff(包括结束符,所以不能用字符串的结束符作为结束标志),只能通过通过协议传输的字节数量来控制结束

void PrintByteN( unsigned char* data_src, // pointer to data source
          unsigned char N) // number of data(byte)
{
  while( N--){
    PrintByte(*(data_src++));
  }
}

原文地址:https://www.cnblogs.com/jieruishu/p/6185625.html