Create a keil project and light up the LED light of the STM32 board

Publisher:TranquilGazeLatest update time:2018-08-15 Source: eefocus Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

Open the previously created project, as shown in the figure below (the creation of the Keil project is in the previous article, and students who don’t know can turn to the previous article.)


(The picture above is a completed project)

Then, open the LED light routine in the routine package of the corresponding development board version we downloaded earlier.

(The path is: en.stsw-stm32077 \STM32L1xx_StdPeriph_Lib_V1.3.1 \project\STM32L1xx_StdPeriph_Examples \GPIO \IOToggle)

Find the mian.c file and open it, select and copy all the contents


Go back to the project we have created before, open the main.c file, clear it, and paste the contents of main.c in the GPIO file into main.c of our project.

At this point, you can see that there are many errors. Next, you need to modify the program (because the definitions of many parameters in the routine are not accurately corresponding to each board, so they need to be modified. In order to achieve the simplest LED light lighting function, we will delete the redundant programs)

The first step is to delete two programs:


(The picture above shows the first program that was deleted)


(The picture above shows the second program that needs to be deleted - all the contents in the while loop)

OK, now the main function has been basically deleted.

The second step is to look at the board. I use STM32L152c-discovery, and the ports of my two LED lights are PB7 and PB6 respectively (the following content needs to be changed according to the board situation)


So, I have to change the D port in the example to the B port first.



(Both of the above should be changed to B, because my LED light is connected to port B)

Step 3: Configure the output mode


Change GPIO_PIN_X and GPIO_PIN_Y to GPIO_Pin_6 and GPIO_Pin_7 respectively. Note that there are two places to change. One is to change XY to 67, because my pins are PB6 and PB7, and the other is to change PIN to Pin, because the mode defined in my version of the library function is like this. After the modification:


Step 4: Modify the loop content (key steps to control LED lights)


Add the program shown in the figure above into while (where you just deleted the second program).

Step 5. Add the declaration of the Delay function (I don’t know if I accidentally deleted the declaration before, or if it was not originally included in the example. If yours has it, you don’t need to add it)


At this point, the program modification is complete, rebuild, and then burn, you can see the two LED lights flashing in a cycle.

It is particularly emphasized that the modification of the program here depends on the port and connection status of your board itself, and you need to check the corresponding ones! (In addition, the explanation of the program is in the picture above, and only two very simple programs are needed!)


Reference address:Create a keil project and light up the LED light of the STM32 board

Previous article:Use STM32GPIO port to light up the LED (library function)
Next article:STM32-Serial port IAP upgrade

Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
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号