国民技术GPIO配置推挽输出模式

该文介绍了如何在单片机开发中设置GPIO为推挽输出模式,包括定义GPIO_Mode枚举类型,初始化GPIO结构体,启用GPIO时钟,设置GPIOPin、电流等级、上下拉方式及模式,并提供了LED控制宏。通过`OutPut_IO_Init`函数实现了GPIO配置和LED状态设置。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

GPIO配置是在开发单片机常用的。下面就来介绍如何将GPIO配置推挽输出模式。

typedef enum
{
    GPIO_Mode_Input =  0x00000000,   /*!< Input Floating Mode                   */
    GPIO_Mode_Out_PP = 0x00000001,   /*!< Output Push Pull Mode                 */
    GPIO_Mode_Out_OD = 0x00000011,   /*!< Output Open Drain Mode                */
    GPIO_Mode_AF_PP =  0x00000002,   /*!< Alternate Function Push Pull Mode     */
    GPIO_Mode_AF_OD =  0x00000012,   /*!< Alternate Function Open Drain Mode    */

    GPIO_Mode_Analog = 0x00000003,   /*!< Analog Mode  */

    GPIO_Mode_IT_Rising = 0x10110000,   /*!< External Interrupt Mode with Rising edge trigger detection          */
    GPIO_Mode_IT_Falling = 0x10210000,   /*!< External Interrupt Mode with Falling edge trigger detection         */
    GPIO_Mode_IT_Rising_Falling = 0x10310000,   /*!< External Interrupt Mode with Rising/Falling edge trigger detection  */

    GPIO_Mode_EVT_Rising = 0x10120000,   /*!< External Event Mode with Rising edge trigger detection               */
    GPIO_Mode_EVT_Falling = 0x10220000,   /*!< External Event Mode with Falling edge trigger detection              */
    GPIO_Mode_EVT_Rising_Falling = 0x10320000
}GPIO_ModeType;
#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;
}

int main(void)
{	
	OutPut_IO_Init();
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值