STM32F103C8T6点亮LED
时间: 2024-04-25 18:06:10 浏览: 59
Sure, to light up an LED using STM32F103C8T6, you need to connect the LED to a GPIO pin of the microcontroller and set the pin to output mode. Then, you can simply toggle the pin high and low to turn the LED on and off. Here's a sample code to do that:
```
#include "stm32f10x.h"
int main(void)
{
// Enable GPIOC peripheral clock
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);
// Configure GPIOC Pin 13 as output push-pull
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOC, &GPIO_InitStructure);
// Toggle LED on and off
while(1)
{
GPIO_WriteBit(GPIOC, GPIO_Pin_13, Bit_SET);
Delay(1000);
GPIO_WriteBit(GPIOC, GPIO_Pin_13, Bit_RESET);
Delay(1000);
}
}
```
Note: This is just a sample code and you may need to modify it according to your specific requirements.
阅读全文