如果LED一端连接GND,一端连接GPIO端口;按键一端连接VDD,一端连接GPIO端口,那么LED_Init()和KEY_Init()应该如何写?此时想点亮LED灯需要什么样的函数
void KEY_Init(void) //IO初始化
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(按键GPIO时钟,ENABLE);
GPIO_InitStructure.GPIO_Pin = 按键引脚;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
GPIO_Init(按键GPIOx, &GPIO_InitStructure);
}
void LED_Init(void) //IO初始化
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(LED_GPIO时钟,ENABLE);
GPIO_InitStructure.GPIO_Pin = LED引脚;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(LED_GPIOx, &GPIO_InitStructure);
GPIO_ResetBits(LED_GPIOx,LED引脚);
}
void LED_Cmd(u8 sw)
{
if(sw)
GPIO_SetBits(LED_GPIOx, LED引脚); //点灯
else
GPIO_ResetBits(LED_GPIOx,LED引脚); //熄灯
}
GPIO驱动电流小,硬件上一般可以用晶体管控制