The example of this paper refers to “STM32 single chip microcomputer development example – based on Proteus virtual simulation and hal/ll library”
Realize the effect of running water lamp.
staySection IAs shown in the figure below, a circuit is added to Proteus, in which we add a drain resistor RX8.
According to the circuit diagram, we can know that when STM32 MCU outputs low level, the LED is on.
Open cubemx and configure pc0-pc7 pin as GPIO according to the setup project_ Output。
Click “project manager” — “advanced settings”, change the GPIO library to the LL Library (we need to use the functions in the LL library later), and click “generator code” to generate the Keil project.
This time, we need to realize the water lamp. We can write each pin separately or use the look-up table method. This time, we use the look-up table method. The corresponding table of LED water lamp status bytes is as follows:
Click “open project” to open the project in keil, and double-click the “main.c” file.
In this simulation, we newly use the write port output function
LL_GPIO_WriteOutputPort()The official document API is shown in the following figure.
We need to read the status bytes of the flow lamp by looking up the table, so we first set an array at the beginning of the function to store the status bytes of the flow lamp.
/* USER CODE BEGIN PV */
Through the loop method, we read the values in the state table array in turn, so we first define a loop variable at the beginning of the main function.
/* USER CODE BEGIN 1 */
Finally, we add the following code to the while loop
/* USER CODE BEGIN WHILE */
- Click Run to generate hex file.
- Load the corresponding hex file in Proteus and click Run. You can see that the LED lights are lit from top to bottom to form a cycle.