TI-TM4C123x学习记录(五):读取高低电平

读取一个引脚的高低电平,最常见的是用在按键判定上,其次是在中断中也有使用。

一、关键语句

int32_t ROM_GPIOPinRead(uint32_t ui32Port, uint8_t ui8Pins)

Parameters: 

ui32Port is the base address of the GPIO port. 

ui8Pins is the bit-packed representation of the pin(s).

二、使用方式

一般来说,读取一个引脚的高低电平需要完成以下步骤

使能GPIO:

SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOM); 

设置输入IO口:

GPIOPinTypeGPIOInput(GPIO_PORTM_BASE, GPIO_PIN_3); 

读值:

int32_t key;
key = ROM_GPIOPinRead(GPIO_PORTM_BASE, GPIO_PIN_3);

三、注意事项

读取值为ui8Pins的值,如:

//初始化引脚
if(ROM_GPIOPinRead(GPIO_PORTM_BASE, GPIO_PIN_3) == GPIO_PIN_3){
//TODO:
}

四、数据手册



猜你喜欢

转载自blog.csdn.net/redgragon0/article/details/80855669