32点第一个灯

发布时间 2024-01-08 11:19:19作者: 浮点数弄不清
#include "stm32f10x.h"                  // Device header
int main()
{
	RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB,ENABLE);
	GPIO_InitTypeDef GPIO_InitStructure;
	GPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_PP;
	GPIO_InitStructure.GPIO_Pin=GPIO_Pin_5;
	GPIO_InitStructure.GPIO_Speed= GPIO_Speed_50MHz;
	GPIO_Init(GPIOB,&GPIO_InitStructure);
	GPIO_SetBits(GPIOB,GPIO_Pin_5);
	//GPIO_ResetBits(GPIOB,GPIO_Pin_5);
	
	while(1)
	{
	}
}

首先开启APB2的时钟,设置一个结构体包含GPIO的模式,引脚和速度,然后初始化GPIO,(GPIO_Init),GPIO_SetBits()和GPIO_ResetBits,是对GPIO端口置1还是0;