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();
}