STM32F103LED代码
时间: 2023-07-23 12:59:41 浏览: 45
您好!以下是一个简单的STM32F103上的LED控制代码示例:
```c
#include "stm32f10x.h"
// 定义GPIO引脚
#define LED_GPIO_PORT GPIOC
#define LED_GPIO_PIN GPIO_Pin_13
int main(void)
{
// 初始化GPIO
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);
GPIO_InitStructure.GPIO_Pin = LED_GPIO_PIN;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(LED_GPIO_PORT, &GPIO_InitStructure);
while (1)
{
// 点亮LED
GPIO_SetBits(LED_GPIO_PORT, LED_GPIO_PIN);
// 延时一段时间
for (int i = 0; i < 1000000; i++);
// 熄灭LED
GPIO_ResetBits(LED_GPIO_PORT, LED_GPIO_PIN);
// 延时一段时间
for (int i = 0; i < 1000000; i++);
}
}
```
以上代码使用了STM32F10x标准外设库,通过控制GPIOC的13号引脚来控制LED的点亮和熄灭。代码中使用了循环延时的方式来产生延时效果,可以根据需要进行调整。
相关推荐
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)