stm32f103c8t6的PC13点灯程序
时间: 2024-08-11 11:01:34 浏览: 57
STM32F103C8T6是一款基于Cortex-M3内核的32位微控制器,它包含GPIO端口用于数字输入输出操作,如LED控制。PC13通常指的是GPIO端口C的第13个引脚,你可以用它来驱动外部设备,比如LED。
下面是一个简单的STM32F103C8T6使用GPIOC的PA13(因为有的资料PC13可能对应的是PA13)点亮LED的示例程序,假设你已经配置了GPIO模式为推挽输出:
```c
#include "stm32f10x.h" // 包含STM32的头文件
// 定义GPIOC寄存器地址和引脚功能
GPIO_TypeDef *GPIOC = GPIOC_BASE;
GPIO_PinState LED_State = GPIO_PIN_SET; // 设置LED为高电平(亮)
int main(void)
{
// 初始化GPIOC并设置PA13为推挽输出
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC, ENABLE); // 启动GPIOC时钟
GPIO_InitTypeDef GPIO_InitStructure;
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); // 点亮LED
__delay_ms(1000); // 暂停1秒
GPIO_ResetBits(GPIOC, GPIO_Pin_13); // 关闭LED
__delay_ms(1000); // 再暂停1秒
}
}
阅读全文
相关推荐
![-](https://img-home.csdnimg.cn/images/20241231044736.png)
![-](https://img-home.csdnimg.cn/images/20241231045053.png)
![-](https://img-home.csdnimg.cn/images/20241231044955.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.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)