1. 程式人生 > >EFM32----->GPIO

EFM32----->GPIO

配置時鐘:

void CMU_ClockEnable(CMU_Clock_TypeDef clock, bool enable)

CMU_ClockEnable(cmuClock_HFPER, true); /* Enable GPIO in CMU */ CMU_ClockEnable(cmuClock_GPIO, true);

配置為輸入:

void GPIO_PinModeSet(GPIO_Port_TypeDef port,
                     unsigned int pin,
                     GPIO_Mode_TypeDef mode,
                     unsigned int out)
/* Configure PB9 and PB10 as input */
GPIO_PinModeSet(gpioPortB, 9, gpioModeInput, 0);
GPIO_PinModeSet(gpioPortB, 10, gpioModeInput, 0);

配置為輸出:

void GPIO_PinModeSet(GPIO_Port_TypeDef port,
                     unsigned int pin,
                     GPIO_Mode_TypeDef mode,
                     unsigned 
int out) GPIO_PinModeSet(ledArray[ledNo].port, ledArray[ledNo].pin, gpioModePushPull, 0);

 

配置為中斷輸入:

先配置為輸入,再配置中斷

GPIO_IntConfig(GPIO_Port_TypeDef port,
                                    unsigned int pin,
                                    bool risingEdge,
                                    
bool fallingEdge, bool enable) /* Set falling edge interrupt for both ports */ GPIO_IntConfig(gpioPortB, 9, false, true, true); GPIO_IntConfig(gpioPortB, 10, false, true, true);