废话不多,GPIO配置是在开发单片机常用的。下面就来介绍如何将GPIO配置输入模式。
#define Led1_Pin GPIO_PIN_5
#define Led1_Port GPIOB
#define Led1_High GPIO_WriteBit(Led1_Port, Led1_Pin, Bit_SET)
#define Led1_Low GPIO_WriteBit(Led1_Port, Led1_Pin, Bit_RESET)
void OutPut_IO_Init(void)
{
GPIO_InitType GPIO_InitStructure;
GPIO_InitStruct(&GPIO_InitStructure);
RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOB, ENABLE);
GPIO_InitStructure.Pin = Led1_Pin;
GPIO_InitStructure.GPIO_Current = GPIO_DC_4mA;
GPIO_InitStructure.GPIO_Pull = GPIO_No_Pull;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitPeripheral(Led1_Port, &GPIO_InitStructure);
Led1_High;
}
#define Key_Pin GPIO_PIN_4
#define Key_Port GPIOA
#define Read_Key_Port GPIO_ReadInputDataBit(Key_Port, Key_Pin)
void InPut_IO_Init(void)
{
GPIO_InitType GPIO_InitStructure;
GPIO_InitStruct(&GPIO_InitStructure);
RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOA, ENABLE);
GPIO_InitStructure.Pin = Key_Pin;
GPIO_InitStructure.GPIO_Pull = GPIO_Pull_Up;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Input;
GPIO_InitPeripheral(Key_Port, &GPIO_InitStructure);
}
int main(void)
{
InPut_IO_Init();
OutPut_IO_Init();
while(1)
{
if(Read_Key_Port == Bit_SET)
Led1_High;
else
Led1_Low;
}
}
2054

被折叠的 条评论
为什么被折叠?



