stm32f103c8t6简单的程序源码
时间: 2023-08-21 13:00:26 浏览: 39
以下是一个简单的STM32F103C8T6的程序源码示例,用于点亮开发板上的LED灯:
```c++
#include "stm32f10x.h"
int main(void)
{
GPIO_InitTypeDef GPIO_InitStruct;
// 打开GPIOC的时钟
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);
// 配置GPIOC为推挽输出模式
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_13;
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStruct.GPIO_Speed = GPIO_Speed_2MHz;
GPIO_Init(GPIOC, &GPIO_InitStruct);
while (1)
{
// 点亮LED灯
GPIO_SetBits(GPIOC, GPIO_Pin_13);
// 延时一段时间
for (int i = 0; i < 1000000; i++);
// 关闭LED灯
GPIO_ResetBits(GPIOC, GPIO_Pin_13);
// 延时一段时间
for (int i = 0; i < 1000000; i++);
}
}
```
这个程序使用STM32标准外设库(ST Standard Peripheral Library)来操作GPIO接口,主要实现了循环点亮和熄灭开发板上的LED灯。首先,需要打开GPIOC的时钟,然后配置GPIOC的第13号引脚为推挽输出模式,接着在一个循环中,先点亮LED灯,然后延时一段时间,再关闭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)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)