代码生成(STM32 点亮LED灯 C程序)
时间: 2023-09-21 16:08:05 浏览: 57
好的,以下是使用 STM32 点亮 LED 灯的 C 语言程序示例:
```c
#include "stm32f10x.h"
int main(void) {
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);
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);
while(1) {
GPIO_SetBits(GPIOC, GPIO_Pin_13);
for (int i = 0; i < 1000000; i++);
GPIO_ResetBits(GPIOC, GPIO_Pin_13);
for (int i = 0; i < 1000000; i++);
}
}
```
以上代码使用了 STM32F103C8T6 开发板上的一个 LED 灯,连接在 PC13 引脚上。程序首先开启 GPIOC 外设时钟,然后使用 `GPIO_Init` 函数初始化 GPIOC 引脚,将 PC13 引脚设置为推挽输出模式,并设置输出速度为 50 MHz。在主程序中,程序使用 `GPIO_SetBits` 函数点亮 PC13 引脚上的 LED 灯,然后使用一个简单的 for 循环进行延时,最后使用 `GPIO_ResetBits` 函数将 PC13 引脚上的 LED 灯熄灭,并再次进行延时。程序将一直循环执行,使 LED 灯不断闪烁。
相关推荐
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_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)