Experiment 2: Create a project

Publisher:幸福自由Latest update time:2017-11-18 Source: eefocus Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

1. Open STVD, File->New Workspace;

2. Double-click Create workspace and project, and enter the name of the workspace in the Workspace filename column. It can be in Chinese or English with spaces. Enter the path of the workspace in the Workspace location column. As shown in the figure below, first find the desktop path in the browse folder, and then click the New Folder button on the right to create a folder. Or directly select an existing path. Click OK;

Experiment 2 Creating a Project

Experiment 2 Creating a Project

3. Enter the name of the project in the Project filename column, select STM8 Cosmic as the compiler in the Toolchain drop-down menu, and click OK;

4. Enter STM8S105K4 or 105K4 in the Show MCUs containing column, click the Select button in the lower left corner, and click OK.

Experiment 2 Creating a ProjectAt this point, the workspace and project have been created. The project contains the following files: main.c, stm8_interrupt_vector.c in the Source Files folder, and mods0.h in the External Dependencies folder.

In the initial stage, before we learned program modularization, the program code was written in the source file main.c (the source file is the file name.c document).

Find the two header files STM8S105K.h and STM8S105K4.h in the C:\Program Files (x86)\STMicroelectronics\st_toolset\include folder, copy and paste them in the root directory of the project, such as the C:\Users\HuHongYu\Desktop\Demo folder in this example.

In the main.c file, write the following code above the main() function.

#include

#include is a keyword in C language, which is used to include header files. STM8S105K4.h is a header file (i.e. file name.h document). This header file declares the address of the microcontroller register. When compiling the program, programming the register means operating the corresponding address of the register in the microcontroller flash. So we need to include this header file in main.c.

C language distinguishes between uppercase and lowercase letters. Except for strings and comments, all codes must be entered in English input method.

The third row of the menu bar has three buttons: the first is Compile, which compiles the current file code; the second is Build, which compiles the modified document and its associated documents; the third is Rebuild All, which recompiles all documents in the project. In the future, we will mainly use the second button Build.

Experiment 2 Creating a Project

After clicking the Build button, the following prompt box appears, select Yes To All.

Experiment 2 Creating a Project

The Build window below shows demo.elf - 0 error(s), 0 warning(s), which means that after the compilation is successful, the header files copied from the ST installation path will appear in the External Dependencies folder. Because STM8S105K.h is included in STM8S105K4.h, the latter is also included in the project after compilation.

There are two buttons in the third row of the menu bar. The first one is Start Debugging, which is used to download the compiled program to the microcontroller for simulation. The second one is Stop Debugging, which is used to exit the simulation.

Experiment 2 Creating a Project

Before downloading the simulation program, first connect the 3.3V, SWIM, GND, and RST pins of the ST-LINK V2 (downloader) to the VCC (3.3V), SWIM, GND, and NRST pins of the STM8 microcontroller. VCC is the power supply (positive power supply), and GND is the ground (negative power supply).

Click the Debug button. If error 40201 appears, open C:\Program Files (x86)\STMicroelectronics\st_toolset\stvd\dao and install the ST Toolset.msi file.

When you exit STVD, the following two prompt boxes will appear. Select Yes. These two prompt boxes will appear every time you create a new project.

Experiment 2 Creating a Project

Experiment 2 Creating a Project

To open the STM8 program project in the future, find the workspace name .stw in the project folder and double-click to open it. If it cannot be opened, use the following two methods:

1. Left-click and select the ***.stw file, drag it to the STVD desktop shortcut icon, and overlap it to open it directly;

2. Open STVD, select File->Open Workspace from the menu bar, and open the ***.stw file.


Reference address:Experiment 2: Create a project

Previous article:Experiment 1: Building a development environment
Next article:Experiment 3 Lighting up an LED

Recommended ReadingLatest update time:2024-11-23 12:01

stm8s003 8K space is not enough, an error occurs, modify the stvd parameters for optimization
The space size of stm8s008 is 8K. When using it, there will be a situation where the space is not enough. At this time, some settings should be made on the software to optimize the program size. 1. Modify the optimization level, as shown in the figure below. This will optimize irrelevant functions and optimize the c
[Microcontroller]
stm8s003 8K space is not enough, an error occurs, modify the stvd parameters for optimization
Programming microcontrollers using STVD and Cosmic C compiler
  Pulse width modulation (PWM) is an analog modulation technique in which the duration or width of a pulse varies over time. It is a commonly used technique for generating a continuous pulse signal with a defined frequency and duty cycle. Simply put, PWM changes the width of the pulse while keeping the frequency const
[Microcontroller]
Programming microcontrollers using STVD and Cosmic C compiler
Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号