求點贊??????
1.硬件設計

image.png
2.相關概念

image.png

image.png
3.代碼
3.1 GPIO操作
GPIO_SetBits(GPIOD,GPIO_Pin_2); //PD.2 輸出高
GPIO_WriteBit(GPIOD,GPIO_Pin_2,Bit_SET); //PD.2 輸出高
GPIO_WriteBit(GPIOD,GPIO_Pin_2,Bit_RESET); //PD.2 輸出低
GPIO_ResetBits(GPIOD,GPIO_Pin_2); //PD.2 輸出低
3.2 初始化
void LED_Init(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA|RCC_APB2Periph_GPIOD, ENABLE); //使能PA,PD端口時鐘
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8; //LED0-->PA.8 端口配置
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //推挽輸出
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //IO口速度為50MHz
GPIO_Init(GPIOA, &GPIO_InitStructure); //根據設定參數初始化GPIOA.8
GPIO_SetBits(GPIOA,GPIO_Pin_8); //PA.8 輸出高
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2; //LED1-->PD.2 端口配置, 推挽輸出
GPIO_Init(GPIOD, &GPIO_InitStructure); //推挽輸出 ,IO口速度為50MHz
GPIO_SetBits(GPIOD,GPIO_Pin_2); //PD.2 輸出高
}