MSP中大家如果配好环境的话可以找到其中的GPIO库函数,接下来我会一一列举出其中的函数,并说明其作用。
//以下是对GPIO函数库中函数的介绍
void GPIO_setAsOutputPin(uint8_t selectedPort, uint16_t selectedPins);
/*该函数为配置GPIO为输出引脚 selectedPort为端口号 selectedPins为引脚号*/
void GPIO_setAsInputPin(uint8_t selectedPort,uint16_t selectedPins);
/*该函数为配置GPIO为输入引脚 selectedPort为端口号 selectedPins为引脚号*/
void GPIO_setOutputHighOnPin(uint8_t selectedPort,uint16_t selectedPins);
/*该函数使GPIO输出为高电平,入口与参数同上*/
void GPIO_setOutputLowOnPin(uint8_t selectedPort,uint16_t selectedPins);
/*该函数使GPIO输出为低电平,入口参数同上*/
void GPIO_toggleOutputOnPin(uint8_t selectedPort,uint16_t selectedPins);
/*引脚取反,入口同上*/
void GPIO_setAsPeripheralModuleFunctionOutputPin(uint8_t selectedPort,uint16_t selectedPins);
/*引脚复用输出,类似STM32中的引脚复用功能,当我们需要引脚其它功能时需要使用这个函数*/
void GPIO_setAsPeripheralModuleFunctionInputPin(uint8_t selectedPort,uint16_t selectedPins);
/*引脚复用输入*/
void GPIO_setAsInputPinWithPullDownResistor(uint8_t selectedPort,uint16_t selectedPins);
/*配置引脚为带下拉电阻输入模式*/
void GPIO_setAsInputPinWithPullUpResistor(uint8_t selectedPort,uint16_t selectedPins);
/*配置引脚为带上拉电阻输入模式*/
uint8_t GPIO_getInputPinValue(uint8_t selectedPort,uint16_t selectedPins);
/*该函数为获取引脚输入的值*/
void GPIO_enableInterrupt(uint8_t selectedPort,uint16_t selectedPins);
/*选用引脚启用中断功能*/
void GPIO_disableInterrupt(uint8_t selectedPort,uint16_t selectedPins);
/*关闭引脚中断功能*/
uint16_t GPIO_getInterruptStatus(uint8_t selectedPort,uint16_t selectedPins);
/*获取引脚中断状态*/
void GPIO_clearInterrupt(uint8_t selectedPort,uint16_t selectedPins);
/*清除引脚标志位*/
void GPIO_selectInterruptEdge(uint8_t selectedPort,uint16_t selectedPins,uint8_t edgeSelect);
/*选择引脚中断为上升沿还是下降沿*/
void GPIO_setDriveStrength(uint8_t selectedPort,uint16_t selectedPins,uint8_t driveStrength);
/*选择引脚的驱动强度*/
//输入参数selectedPort:- \b GPIO_PORT_P1
//! - \b GPIO_PORT_P2
//! - \b GPIO_PORT_P3
//! - \b GPIO_PORT_P4
//! - \b GPIO_PORT_P5
//! - \b GPIO_PORT_P6
//! - \b GPIO_PORT_P7
//! - \b GPIO_PORT_P8
//! - \b GPIO_PORT_P9
//! - \b GPIO_PORT_P10
//! - \b GPIO_PORT_P11
//! - \b GPIO_PORT_PA
//! - \b GPIO_PORT_PB
//! - \b GPIO_PORT_PC
//! - \b GPIO_PORT_PD
//! - \b GPIO_PORT_PE
//! - \b GPIO_PORT_PF
//! - \b GPIO_PORT_PJ
//selectedPins:- \b GPIO_PIN0
//! - \b GPIO_PIN1
//! - \b GPIO_PIN2
//! - \b GPIO_PIN3
//! - \b GPIO_PIN4
//! - \b GPIO_PIN5
//! - \b GPIO_PIN6
//! - \b GPIO_PIN7
//! - \b GPIO_PIN8
//! - \b GPIO_PIN9
//! - \b GPIO_PIN10
//! - \b GPIO_PIN11
//! - \b GPIO_PIN12
//! - \b GPIO_PIN13
//! - \b GPIO_PIN14
//! - \b GPIO_PIN15
//! - \b GPIO_PIN_ALL8
//! - \b GPIO_PIN_ALL16
//edgeSelect:- \b GPIO_HIGH_TO_LOW_TRANSITION
//! - \b GPIO_LOW_TO_HIGH_TRANSITION
//driveStrength: - \b GPIO_REDUCED_OUTPUT_DRIVE_STRENGTH
//! - \b GPIO_FULL_OUTPUT_DRIVE_STRENGTH
以上是对其函数功能的介绍,再下来我们介绍一下其中的GPIO具体包括哪些:
数字I/O功能包括:独立可编程的单个I/ o
输入或输出的任何组合单独配置P1和P2中断
某些设备可能包含额外的端口中断
独立的输入和输出
数据寄存器单独配置的上拉或下拉电阻
端口P1和P2始终具有中断能力,单独分配中断源。端口P1、P2可以合成为PA,P3、P4可以合成为PB等等。
GPIO驱动强度默认为低驱动强度,以减少电磁干扰
以下是引脚输出高电平代码
WDT_A_hold(WDT_A_BASE);
//关闭看门狗
//配置P1、P2引脚为输出
GPIO_setAsOutputPin(
GPIO_PORT_PA,
GPIO_PIN0 + GPIO_PIN1 + GPIO_PIN2 + GPIO_PIN3 +
GPIO_PIN4 + GPIO_PIN5 + GPIO_PIN6 + GPIO_PIN7 +
GPIO_PIN8 + GPIO_PIN9 + GPIO_PIN10 + GPIO_PIN11 +
GPIO_PIN12 + GPIO_PIN13 + GPIO_PIN14 + GPIO_PIN15
);
//将P1、P2引脚置1
GPIO_setOutputHighOnPin(
GPIO_PORT_PA,
GPIO_PIN0 + GPIO_PIN1 + GPIO_PIN2 + GPIO_PIN3 +
GPIO_PIN4 + GPIO_PIN5 + GPIO_PIN6 + GPIO_PIN7 +
GPIO_PIN8 + GPIO_PIN9 + GPIO_PIN10 + GPIO_PIN11 +
GPIO_PIN12 + GPIO_PIN13 + GPIO_PIN14 + GPIO_PIN15
);