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

 

配置引脚为中断输入:

中断初始化:

void GPIOINT_Init(void)
{
  NVIC_ClearPendingIRQ(GPIO_ODD_IRQn);      //清除奇数引脚中断标志
  NVIC_EnableIRQ(GPIO_ODD_IRQn);             //使能奇数引脚中断
  NVIC_ClearPendingIRQ(GPIO_EVEN_IRQn);     //清除偶数引脚中断标志
  NVIC_EnableIRQ(GPIO_EVEN_IRQn);            //使能偶数引脚中断
}

 

先配置为输入,再配置中断

__STATIC_INLINE void 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);

 

 引脚输出高电平:

__STATIC_INLINE void GPIO_PinOutSet(GPIO_Port_TypeDef port, unsigned int pin)

GPIO_PinOutSet(ledArray[ledNo].port, ledArray[ledNo].pin);

 

引脚输出低电平:

__STATIC_INLINE void GPIO_PinOutClear(GPIO_Port_TypeDef port, unsigned int pin)

GPIO_PinOutClear(ledArray[ledNo].port, ledArray[ledNo].pin);

 

引脚翻转输出电平:

__STATIC_INLINE void GPIO_PinOutToggle(GPIO_Port_TypeDef port, unsigned int pin)

GPIO_PinOutToggle(ledArray[ledNo].port, ledArray[ledNo].pin);

 

读取输出引脚电平:

__STATIC_INLINE unsigned int GPIO_PinOutGet(GPIO_Port_TypeDef port,
                                            unsigned int pin)

retVal = (int)GPIO_PinOutGet(ledArray[ledNo].port, ledArray[ledNo].pin);

 

读取输入引脚电平:

__STATIC_INLINE unsigned int GPIO_PinInGet(GPIO_Port_TypeDef port,
                                           unsigned int pin)

 

读取输入端口:

__STATIC_INLINE uint32_t GPIO_PortInGet(GPIO_Port_TypeDef port)

 

转载于:https://www.cnblogs.com/jxndsfss/p/10127897.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值