STM32 控制 LED 亮灭代码示例
#include 'stm32f10x.h'
int main(void) { GPIO_InitTypeDef GPIO_InitStructure;
// 使能 GPIOA 时钟
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
// 配置 GPIOA.0 为输出模式
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);
while(1)
{
// 点亮 LED
GPIO_SetBits(GPIOA, GPIO_Pin_0);
// 延时
for(int i=0; i<1000000; i++);
// 熄灭 LED
GPIO_ResetBits(GPIOA, GPIO_Pin_0);
// 延时
for(int i=0; i<1000000; i++);
}
}
原文地址: https://www.cveoy.top/t/topic/lW9P 著作权归作者所有。请勿转载和采集!