打印
[综合信息]

国民技术GPIO配置输入模式

[复制链接]
37|0
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
wowu|  楼主 | 2025-3-23 14:13 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
废话不多,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;
        }       
}



————————————————

                            版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。

原文链接:https://blog.csdn.net/dailin2012/article/details/129726704

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

109

主题

4192

帖子

1

粉丝