﻿ 算法 – 将数据发送到串口的最佳方法是什么？ - 代码日志

#### 算法 – 将数据发送到串口的最佳方法是什么？

1. In Microcontroller there is an Analog to Digital converter with 10
bit resolution. (It will output a
value between 0 and 1023)

2. I need to send this value to PC using the serial port.

3. But you can only write 8 bits at once. (You need to write bytes). It is
a limitation in micro controller.

4. So in the above case at least I need to send 2 bytes.

5. My PC application just reads a sequence of numbers for plotting. So
it should capture two consecutive
bytes and build the number back. But
here we will need a delimiter
character as well. but still the delimiter character has an ascii value between 0 – 255 then it will mixup the process.

``````Ex : 1023 = "1""0""2""3" Vs "Char(255)Char(4)"
``````

>不需要分隔符(您可以通过0或1判断您正在读取哪个字节)
>你绝对可以发现任何1位错误,所以你知道坏数据

>假设我想发送714 = 1011001010.
>分成2 10110,01010
>添加位以指示第一个和第二个字节010110,101010
>计算每一半的奇偶校验：p0 = par(010)= 1,q0 = par(110)= 0,p1 = par(101)= 0,q1 = par(010)= 1
>字节然后是10010110,01101010

>字节0：0(7位)
>字节1：1(7位)
>字节2：1(7位)
>字节3：1(7位)
>字节4：0(7位)
>字节5：0(7位)
>字节6：(8位)

>字节0：0(7位)7
>字节1：1(7位)14
>字节2：1(7位)21
>字节3：1(7位)28
>字节4：1(7位)35
>字节5：1(7位)42
>字节6：0(7位)49
>字节7：(8位)57
>字节8：(8位)65
>字节9：(8位)73
>字节10：(8位)81
>字节11：0(7位)88
>字节12：(8位)96
>字节13：(8位)104
>字节14：(8位)112
>字节15：(8位)120