Use virtual serial port to debug serial port in keil MDK

Function introduction:
Without using the 32 development board, use the software emulation in keil MDK and the virtual serial port software VSPD to complete the process of serial communication.

Similar articles use the virtual serial port to debug the serial port in the keil C51 using the C51 microcontroller to debug the serial port

The operation steps are as follows:
1. Open the virtual serial port software and
click Add Port: Use VSPD to connect the two virtual serial ports on the PC. Connect COM1 and COM2 as shown.
insert image description here
It can be seen that two virtual serial ports are connected together on Virtual ports, so that serial port 1 and serial port 2 can communicate.
insert image description here
2. Open the serial port assistant software
Open the serial port 1, set the baud rate to 9600, the data bit to 8, the parity bit to none, and the stop bit to 1
insert image description here
3. Open a 32 project file that has written serial communication and
click the magic wand to enter Debug Settings page, select Use Simulator. In this way, the software simulation can be performed.
insert image description here
Click to enter the software simulation
insert image description here
. After clicking the simulation, the interface is as follows
insert image description here
. Enter the following two commands in the input line of the command window, and press the Enter key to complete the input.

MODE COM2 9600,0,8,1
ASSIGN COM2 <S1IN> S1OUT

insert image description here
After clicking Run at full speed, you can see the output of the serial port in the serial port window.
insert image description here
At the same time, we can also see the output content
insert image description here
command description on the serial port assistant:
1. MODE COM2 9600,0,8,1
Set serial port 1. The baud rate is 9 600, no parity bit, 8 data bits, 1 stop bit.
The function of the MODE command is to set the parameters of the serial port of the bound computer.
The basic usage is: MODE COMx baudrate, parity, databits, stopbits
Among them:
COMx (x = 1, 2, ...) represents the serial port number of the computer;
baudrate represents the baud rate of the serial port; parity represents the check mode;
databits represents the data bits length;
stopbits represents the length of stop bits.

2. ASSIGN COM2 < S1IN > S1OUT
Command 2 is to bind the serial port 2 of the computer to the serial port 1 of the microcontroller.
COMx represents the serial port of the computer, which can be COM1, COM2, COM3 or others;
inreg and outreg represent the serial port of the microcontroller. For ordinary microcontrollers with only one serial port, namely SIN and SOUT; for microcontrollers with two or more serial ports, namely SnIN and SnOUT (n=0, 1, ... the serial port number of the microcontroller).
For example: ASSIGN COM2 < SIN > SOUT
binds the serial port 2 of the computer to the serial port of the microcontroller (for the microcontroller with only one serial port).
ASSIGN COM2 < S1IN > S1OUT
binds the serial port 2 of the computer to the serial port 1 of the microcontroller (for microcontrollers with multiple serial ports, pay attention to the location of the serial port number).
It should be noted that the parentheses of parameters cannot be omitted, while outreg does not have parentheses.

Part of the code implementation:
main.c file

#include "system.h"
#include "SysTick.h"
#include "led.h"
#include "usart.h"

int main()
{
    
    
	u8 i=0; 
	u16 data=1234;
	float fdata=12.34;
	char str[]="Hello World!";	
	SysTick_Init(72);
	NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);  //中断优先级分组 分2组
	LED_Init();
	USART1_Init(9600);
	
	while(1)
	{
    
    
		i++;
		if(i%200==0)
		{
    
    
			led1=!led1;
			
			printf("输出整型数data=%d\r\n",data);
			printf("输出浮点型数fdata=%0.2f\r\n",fdata);
			printf("输出十六进制数data=%X\r\n",data);
			printf("输出八进制数data=%o\r\n",data);
			printf("输出字符串str=%s\r\n",str);
		}
		delay_ms(10);
	}
}

Finally:
those who need code and software can download it by themselves. Resource download link description
Download operation:
insert image description here

Guess you like

Origin blog.csdn.net/NICHUN12345/article/details/124423615