About string output and binary data stream output of serial port

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.