串口輸出的類型主要分為單字節 字符串和二進制數據流,它們的控制輸出函數各不相同。
Windows系統里面,每行結尾是“ <回車><換 行>”,即“\r\n”
#define CR 0x0d // 回車13='\r'
#define LF 0x0a // 換行newline =10='\n'
#define BLK 0X20 //空格= 32=' '
#define END 0 //空格= 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!= ' \0')
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++));
}
}