The type of serial port output is mainly divided into single byte string and binary data stream, and their control output functions are different.
Inside the Windows system, each line ends with "< enter >< wrap >", or "\ r \ n"
#define CR 0x0d//Enter= ' \ r '
#define LF 0x0a//Line newline =10= ' \ n '
#define BLK 0X20//space = 32 = "
#define END 0//space = 0 = ' + '
One-character output:
#include <intrins.h>
void Printbyte (unsigned char byte_data)
{
while (BUSY = = 1) {
}
Printer_data = Byte_data;
NSTB = 0;
_nop_ (); Adjust NSTB letter Pulse Width
NSTB = 1;
}
Two-string output:
void printstring (char* str)
{
While (*str! = 0)
while (*str! = ' + ')
while (*STR)//above can be, that is, as long as not the Terminator
{
Printbyte (* (str++));//Note brackets and + +
}
}
Printing examples
Printstring ("Beijing Wei Huang WH");
Printbyte (CR);
Three-Data flow: Because the data range is 0x00~0xff (including Terminator, so the terminator of the string cannot be used as the end flag), the end can only be controlled by the number of bytes transferred through the protocol.
void Printbyten (unsigned char* data_src,//pointer to data source
unsigned char N)//Number of data (byte)
{
while (n--) {
Printbyte (* (data_src++));
}
}
About string output and binary data stream output of serial port