https://www.cnblogs.com/yangfengwu/p/11100552.html
In this section, let the host computer control the PWM duty cycle signal output by the Wi-Fi pin, and the brightness of the lamp can be controlled by the host computer.
You can extend the program to control the rotation angle of the servo
Double click
textBox3.Text = trackBar1.Value.ToString();//Display the value of the current slider
Then stipulate the agreement, pay attention to the versatility of the project for everyone in the future, and use it for data transmission.
Talk about a knowledge point
How do you transmit decimal data? How do you transmit floating-point data? Baidu download IEEE754
Take a look at the magical use of it for data conversion
I said directly
Suppose you want to send 220.5
this way
Let's create a new data_dispose.h file
To prevent others from using my source code to compile in C++
typedef union Resolve//Analysis of data { char Data_Table[4];//16 hexadecimal four-byte representation float DataF;//Floating point type long DataInt;//Signed integer unsigned long DatauInt;//Unsigned integer } ResolveData;
See now to use
Suppose I collected the instrumentation. The instrumentation is the 220.5 floating-point data sent by the IEEE754 specification. 0x43 0x5C 0x80 0x00
I now need to convert to 220.5
Pay attention to one thing 0x43 0x5C 0x80 0x00 is the high-order data first
For example: 259
Converted to hexadecimal, it is 0x01 0x03, so the sorting is high order first
How to convert the hexadecimal number to 259, that is, 0x01==1, multiplying 1 by 2 to the 8th power, and adding 0x03 to the power of 3.
1*256 + 3 = 259
If the calculation is done, the memory is stored like this
Say a noun: big-endian mode
If the high bit of data is stored in the low bit of the storage address, the low bit of data is stored in the high bit of the storage address -----Name: Big-endian mode
The opposite is little endian
The low bit of data is stored in the low bit of the storage address The high bit of data is stored in the high bit of the storage address -----Name: Little-endian mode
If you have made instruments and meters, or used instruments and meters, you should know that they are often used in industry
Then remind
51 single-chip microcomputer storage data is big-endian mode
STM32 is little-endian
Computer: Little-endian mode
Phone: It seems to be in big-endian mode...forgot
The 8266 little-endian mode we use
Someone may ask, how do you see it in detail...
Look at
First remember
Pay attention to one thing 0x43 0x5C 0x80 0x00 is the high-order data in the front, the low-order data in the back
I tested it just now, and the official printf does not support printing floating point numbers...
So I wrote a printf function myself
void sendstring(unsigned char *string)//here *string is equivalent to an array { while(*string!='\0')//Determine whether the end of the string is reached { USART_SendData(UART0, *string); string++; } } void uart_printf(const char *fmt,...)//Use the same as printf { va_list ap; char string[200];//Cache, if you send more than this number, please increase va_start(ap,fmt); vsprintf(string,fmt,ap);//The sprintf function can also be used here, the usage is similar, just a little modification, here sendstring(string); va_end(ap); }
Print it first
Now let's convert the floating-point data to a hexadecimal array for storage
It comes out 0xcd 0x4c 0xbe 0x43
Since 8266 is in little-endian mode, the low bit is in the front and the high bit is in the back.
The above mainly explains how to convert hexadecimal and floating-point numbers in accordance with the IEEE754 protocol
In fact, testing big endian and little endian is very simple
Anyway, you know that 259 is 0x01 0x03 0x01 is high
You can
It means that the data is in the low bit and the low bit is high in the high bit, so it is little-endian mode
In fact, you just need to know
It’s really not good. When you parse it, turn it upside down.
Let's put the rest to the next section, digest and digest first
https://www.cnblogs.com/yangfengwu/p/11104167.html