VS Code writing Keil project

1 Introduction

Keil C51 is the most classic introductory IDE. Despite its powerful functions, the interface is not very friendly, and it does not support common code auto-completion, code refactoring and other basic functions. When the amount of code increases, program writing, calling, viewing, It is very inconvenient to modify and so on. I learned about the commonly used development tool software on the Internet, and finally chose VS Code instead of Keil to record and share the process, which is also convenient for later viewing.

The Keil code completion setting on the Internet is only for the MDK version Keil MDK 5 code completion function setting , Keil C51 does not support code completion! ! !

Usually a development tool software needs to be rebuilt, which is very troublesome, but using the VS Code + Keil Assistant plug-in can make this process very simple. I want to thank the great god who developed this plugin.

2. Use restrictions

VS Code is a code editor. By installing a plug-in, it only realizes the basic compiling and downloading functions of Keil as an IDE. It cannot completely replace keil, because the plug-in only uses the keil compiler, which is enough in most cases. But there are still some limitations:

  1. Debugging needs to go back to Keil
  2. The addition or deletion of project files needs to be done in keil (will be discussed later)

3. Install VS Code and plugins

VS Code official website: https://code.visualstudio.com/
download and install the VS Code, select the stable version for Windows can
Insert picture description here
to Chinese language plug-ins, for example, point to the left of plug-in button to search chinese, you can choose to install Chinese Simplified , The installation of other plug-ins is similar. (Most of the plug-ins can be used directly after installation, and you need to restart VS Code to set the language to Chinese.)
Insert picture description here
The plug-ins that need to be installed:
Keil Assistant
Insert picture description here
C/C++ IntelliSense (PS: This plug-in is installed, just ignore it, nothing To be set)
Insert picture description here

4. Setting and use of Keil Assistant

Open Keil Assiatant's extended settings, fill in the path of UV4.exe to the corresponding location. Keil C51 is used here, if it is Keil MDK, fill it in below.
Insert picture description here
Note that the full path ends with UV4.exe, the default installation path is C:\Keil_v5\UV4\UV4.exe
Insert picture description here
and then you can add the Keil project to VS Code:
Insert picture description here
View the project code you just added:
Insert picture description here
Click here to compile, or press F7 to compile :
Insert picture description here
Compiler output information is exactly the same as Keil, Ctrl+click can quickly locate the error location.
Insert picture description here
Regarding the second point of the previous use restriction, the addition or deletion of project files needs to be performed in keil, here is a further explanation: because the file directory of keil is updated when keil is closed.

For example, if you want to add a project folder or add a .c.h file, just like using Keil directly, you need to add the file to the Project window on the left of keil, and then close keil, it will automatically update to VS Code, otherwise it will be in VS Code The compilation will report an error because the file cannot be found.
Insert picture description here
Through the above settings, it is not difficult to find that the Keil Assiatant plug-in just calls the local Keil compiler in VS Code, so the compilation option settings of the project need to be set back in Keil, such as the location of the generated .HEX file.
Insert picture description here
Then you can use VS Code to write code happily. VS Code has many useful code editing functions and techniques. You can check the related VS Code tutorials. I recommend a big guy to summarize the VS Code usage skills .

5. Other

The directly added project will display the folders we don’t need, which can be set in setting.json under the .vscode folder. Refer to VSCode to hide unnecessary files in the project
Insert picture description here
. Almost all settings in VS Code are set through json Yes, so it is necessary to be familiar with this mode (when I first used it, I wanted to set a certain function, and I always wanted to find the set button...).

Before contacting VS Code, I also used source insight and learned a little about eclipse.

Compared with VS Code, eclipse is a powerful integrated development environment, mainly used for java. It can also support C/C++ well through extension, but the interface is cumbersome, not light enough, and not very friendly to use. It is used to write a C51 It's a bit of a sledgehammer. Moreover, there is no ready-made plug-in or script that can directly compile the Keil C51 project, and the compilation has to go back to Keil.

Source insight is just a code editor, which is very good when used to view the source code of larger software projects, but the compilation also has to go back to Keil, and the interface feels not as beautiful as VS Code (personal feeling, do not spray).

VS Code has at least three plugins to support Keil compilation, including the previous Keil Assistant, and the other two plugins are Platform IO IDE and EIDE.

Platform IO IDE needs to be used online, which is not convenient. The configuration of EIDE is a little troublesome, and both plug-ins are compiled with SDCC tool chain. The source code is slightly different from Keil C. The existing project code may not be directly compiled. , Some modifications are needed.

VS Code has many powerful plug-ins, and there are many materials on the Internet, you can search by yourself.

Related links:
VS Code custom C code template

VS Code custom color scheme

Guess you like

Origin blog.csdn.net/weixin_42663377/article/details/109984406