I read a lotArticleAnd writes are very simple (actually very simple :)). A detailed tutorial is provided.
1. Use vspd to connect two virtual serial ports on the PC. I connect com2 and com3. Click ADDR pair.
2. We can see that two virtual serial ports are connected together on virtual ports.
3. The virtual serial port is ready. First, you can directly enter the command for debugging. We open the Keil MDK and set it to the simulation mode. Click Debug. Enter mode com2 38400, 0, 8, 1 in the Command serial port.
Note:
The mode command is used to set parameters for the serial port of the bound computer. Basic usage:
Mode comx baudrate, parity, databits, stopbits
Where:
Comx (x = 1, 2 ,...) Indicates the serial port number of the computer;
Baudrate indicates the baud rate of the serial port; Parity indicates the verification method;
Databits indicates the data bit length;
Stopbits indicates the length of the stop bit.
Example: Mode COM1 9600, N, 8, 1
Set Serial Port 1. The baud rate is 9 600, with no check bit. The data is 8 bits and the stop bit is 1 bits.
Mode com219200, 1, 8, 1
Set Serial Port 2. The baud rate is 19 200. It is used for odd verification, 8-bit data, and 1-bit stop bit.
4. Press enter and enter assign com2 <s1in> s1out.
Note:
Comx indicates the serial port of the computer, which can be COM1, com2, com3 or other;
Inreg and outreg represent the serial port of the microcontroller. Common single-chip microcomputer with only one serial port, I .e. sin and sout; single-chip microcomputer with two or more serial ports, namely snin and snout (n = ,... That is, the serial port number of the single chip microcomputer ).
Example: Assign COM1 <sin> sout
Bind Serial Port 1 of the computer to the serial port of the single-chip microcomputer (for single-chip microcomputer with only one serial port ).
Assign com2 <sin> sout
Bind Serial Port 2 of the computer to serial port 0 of the single chip microcomputer (for single chip microcomputer with multiple serial ports, pay attention to the serial port number position ).
Note that the parameter brackets cannot be omitted, while outreg does not.
5. then DEBUGProgram. We can see that the serial port com3 prints the data of Serial Port 1.