Blinking LEDs | Simulation in Proteus in the STM32 Blue Pill | STM32 | STM32CUBEIDE | STM32 project

Опубликовано: 12 Июль 2026
на канале: Tahsan Hasan
1,240
13

#blinkingled #stm32 #stm32cubeide #proteus8 #blink #led

:::Requirement':::

• Blinking L E D :-

• When the switch is KEPT open,the input pin is CONTINUOUSLY HIGH, the LED with Pin 4 will glow continuously and that with Pin 5 will toggle at every 100 mS.
• When the switch is KEPT closed,the input pin is LOW, the LED with Pin 4 will toggle at every 100 mS and that with Pin 5 will glow continuously.



*Steps to start the project:

1. Open STM32CubeIDE.
2. Select File--)Switch Workspace--)others
(Then set workspace where you want to keep your project file)

*Steps to create the project:

1. Choose File--) New --) STM32 Project.
2. Target section-“Commercial Part Number“ box enter "STM32F103C8T6” and select the part from the list on the Right side.
3. choose a project name.
4. press Finish button.

*Pinout and configuration:
1.define output pin two L E Ds and two input pin is switch pin.
2.select system core--) GPIO-configuration-change the setting of input PIN TO pullup from 'GPIO Pull-up/Pull-down' because our requirement is When the switch is KEPT open,the input pin is CONTINUOUSLY HIGH.
3.Under System core choose RCC--)Set High speed clock(HSE)as crystal ceramic resonator.
4.set the clock frequency on 72mHZ (Places where changes to be made)
5.When all settings are done, press ctrl+s to save the setting.(Do you want to code generate--) select "Yes"
6.write the code for your project requirements(use c)

*Generate the .hex file to simulate in proteus:
1.after writting the code,then generate the hex file.
steps to generate the hex file:
1.select Project--properties--C/C++ Build--settings--MCU Post build outputs-
select "convert to binary file(-o binary)"
select "convert to Intel Hex file(-o iHex)"
Then select apply and close.
2.select the debug from the bottom window.
3.show the console display .


*Steps to start the project in Protues:
1.File--New project
2.Select-- Select component Mode from left Icons
3.To add power and ground select Terminals Mode






Code:
#include "stdbool.h"
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_4, 0);
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_5, 0);
while(1)
{
b=HAL_GPIO_ReadPin(GPIOA, GPIO_PIN_7);
if(b) {
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_4, 1);
HAL_GPIO_TogglePin(GPIOA, GPIO_PIN_5);
HAL_Delay(100);
}
else {
HAL_GPIO_TogglePin(GPIOA, GPIO_PIN_4);
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_5, 1);
HAL_Delay(100);
}