Article Directory
====>>> Article summary (with code summary) <<<====
1. Hardware used
Punctual atom Mini board, the main control STM32F103RCT6.
Peripherals used: LED, buttons. Schematic:
2. Generate project
2.1. Create a project
2.2. Search and double-click to select the main control chip
2.3. Configuration
Configure the clock source
Configure the debug mode (you can check it if you need ST-Link download and debug)
Configure the clock tree (you can directly enter 72 in HCLK, and then press Enter to automatically configure)
2.4. Configuration project directory
If checked, c files and header files will be generated separately
2.5. Peripherals used in configuration
PA8: LED0.
PC5: KEY0, configuration input mode, key scanning.
2.6. Generate code
After the configuration is complete, click Generate Code.
3. Directory structure
The generated project directory is as follows:
Core: The source files and header files of the peripherals used in the software generation, main.c is also here. Equivalent to User + Hardware in MDK.
Drivers: HAL library driver files, chip startup files.
MDK-ARM: MDK project file. Enter the MDK-ARM directory to open the project.
4. Code
Add the following code in main.c.
while (1)
{
if(0 == HAL_GPIO_ReadPin(KEY0_GPIO_Port, KEY0_Pin))
{
HAL_Delay(20);
if(0 == HAL_GPIO_ReadPin(KEY0_GPIO_Port, KEY0_Pin))
{
// 输出高电平
// HAL_GPIO_WritePin(LED0_GPIO_Port, LED0_Pin, GPIO_PIN_SET);
// 输出低电平
// HAL_GPIO_WritePin(LED0_GPIO_Port, LED0_Pin, GPIO_PIN_RESET);
// 反转
HAL_GPIO_TogglePin(LED0_GPIO_Port, LED0_Pin);
}
}
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
}
Among them: pin aliases such as LED0_GPIO_Port and LED0_Pin are defined in main.h.
5. Effect verification
Compile, burn, and view the results.
Effect: Press the button and the LED will reverse.