能否提供一份Keil uVision 5编译器下STM32F103RCT6开发板的基本点亮LED灯的示例源代码?
时间: 2024-10-20 16:08:25 浏览: 44
当然可以,下面是一个基本的Keil uVision 5编译器下,使用STM32F103RCT6开发板(如Blue Pill)点亮LED灯的示例C语言源代码:
```c
#include "stm32f10x.h" // 包含STM32的头文件
// 硬件初始化函数
void led_init(void) {
GPIO_InitTypeDef GPIO_InitStructure; // 定义GPIO口配置结构体
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE); // 启动GPIOA的时钟
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0; // LED灯连接到GPIOA的Pin 0
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; // 推挽输出模式
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; // 高速
GPIO_Init(GPIOA, &GPIO_InitStructure); // 初始化GPIO口
}
int main(void) {
led_init(); // 初始化LED灯
while (1) { // 无限循环
GPIO_SetBits(GPIOA, GPIO_Pin_0); // 设置LED灯高电平,点亮
HAL_Delay(1000); // 暂停1秒
GPIO_ResetBits(GPIOA, GPIO_Pin_0); // 设置LED灯低电平,熄灭
HAL_Delay(900); // 暂停900毫秒以平衡闪烁效果
}
return 0;
}
```
在这个示例中,我们首先开启了GPIOA时钟,然后配置了LED灯的GPIO引脚为推挽输出模式,并设置初始状态为低电平(LED关闭)。主循环里,我们交替点亮和熄灭LED。
阅读全文
相关推荐
![-](https://img-home.csdnimg.cn/images/20241231045053.png)
![-](https://img-home.csdnimg.cn/images/20241231045053.png)
![-](https://img-home.csdnimg.cn/images/20241231044955.png)
![-](https://img-home.csdnimg.cn/images/20241231045053.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![7z](https://img-home.csdnimg.cn/images/20241231044736.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![-](https://img-home.csdnimg.cn/images/20241231045053.png)
![-](https://img-home.csdnimg.cn/images/20241231045053.png)
![-](https://img-home.csdnimg.cn/images/20241231045053.png)
![-](https://img-home.csdnimg.cn/images/20241231044955.png)
![-](https://img-home.csdnimg.cn/images/20241231044736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)