f103c8t6最小系统 led 程序
时间: 2023-09-08 15:03:37 浏览: 38
f103c8t6是一款基于ARM Cortex-M3内核的微控制器,可以用来开发各种嵌入式系统。在该微控制器上运行的程序可以通过LED来显示不同的状态或者实现一些特定的功能。
针对f103c8t6的最小系统的LED程序,我们首先需要了解硬件连接。通常情况下,LED的长脚(阳极)连接到MCU的GPIO引脚,短脚则连接至地(GND)。接下来,我们可以编写如下的LED程序:
```c
#include "stm32f10x.h"
void delay_ms(uint32_t time) {
uint32_t i;
for (i = 0; i < time; i++) {
for(uint32_t j = 0; j < 7200000; j++);
}
}
int main(void) {
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE); // 使能GPIOC的时钟
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13; // 将GPIOC的13号引脚设置为输出模式
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; // GPIO频率设置为50Mhz
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; // 推挽输出模式
GPIO_Init(GPIOC, &GPIO_InitStructure); // 应用配置到GPIOC
while (1) {
GPIO_SetBits(GPIOC, GPIO_Pin_13); // 将GPIOC的13号引脚置高,点亮LED
delay_ms(1000); // 延时1000ms
GPIO_ResetBits(GPIOC, GPIO_Pin_13); // 将GPIOC的13号引脚置低,熄灭LED
delay_ms(1000); // 延时1000ms
}
}
```
以上的代码是一个简单的LED程序示例。程序会不断地循环点亮和熄灭GPIOC的13号引脚,实现LED的闪烁效果。通过在主循环中添加想要的功能或者状态判断,可以实现更复杂的LED程序。
需要注意的是,在编写代码之前,需要在开发环境中配置好相关的开发工具和编译环境,以及将所需的头文件添加到工程中。这样才能轻松地将代码下载到f103c8t6微控制器并运行。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.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)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)