LED Control

The tutorial demonstrates controlling the LED on and off.

Hardware connection

image-20240825204711670

PeripheralsDevelopment BoardDescription
LEDPB3The anode of the LED is connected to the development board PB3, and the cathode is connected to the development board GND

Control principle

By controlling the PB3 pin to output high and low levels, the LED can be turned on and off.

Control pinOutput levelLED effect
PB3Output low levelLED off
PB3Output high levelLED on

Bit-band operation

Using bit-band operation, you can read and write a single bit of the memory.

Range of two memory areas supporting bit-band operation

Bit-band alias area

A: byte address

n: bit number (0≤n≤7)

Advantages

You can directly control the bits of the hardware register to improve program execution efficiency!

Code

Example

PB3 output low

The following code actually works the same, the bitband operation is relatively simpler and faster!

Software configuration

Pin definition

 pin of the main control chipmain function (after reset)default reuse functionredefine function
STM32F103RCT6PB3JTDOSPI3_SCK/I2S3_CKPB3/TRACESWO TIM2_CH2/ SPI1_SCK

Software code

Since the default function of the PB3 pin is the JTDO function, we need to disable its function and configure the PB3 as a normal IO pin function.

control function

The tutorial only briefly introduces the code, the specific can open the project source code to read.

Init_Led_GPIO

Experimental phenomenon

The LEd.hex file generated by the project compilation is located in the OBJ folder of the LED project, find the corresponding LEd.hex file of the project and use FlyMcu software to download the program into the development board.

After the program is successfully downloaded, the LED switches on and off every 500ms.