LPC NXP 设置管脚功能为GPIO且为输出的步骤

GPIO_SetDir(CS0_PORT_NUM, (1<<CS0_PIN_NUM), 1);  // 设置为输出
FIO_SetMask(CS0_PORT_NUM,(1<<CS0_PIN_NUM),0);    // 对应管脚掩码设置0
 
。。。。。。
        GPIO_ClearValue(CS1_PORT_NUM, (1<<CS1_PIN_NUM));  // 输出低电平
。。。。。。。
        GPIO_SetValue(CS1_PORT_NUM, (1<<CS1_PIN_NUM));    //输出 高电平


 

 

/*********************************************************************//**
 * @brief		Clear Value for bits that have output direction on GPIO port.
 * @param[in]	portNum		Port number value, should be in range from 0 to 4
 * @param[in]	bitValue	Value that contains all bits on GPIO to clear,
 * 							in range from 0 to 0xFFFFFFFF.
 * 							example: value 0x5 to clear bit 0 and bit 1.
 * @return		None
 *
 * Note:
 * - For all bits that has been set as input direction, this function will
 * not effect.
 * - For all remaining bits that are not activated in bitValue (value '0')
 * will not be effected by this function.
 **********************************************************************/
void GPIO_ClearValue(uint8_t portNum, uint32_t bitValue)
{
	LPC_GPIO_TypeDef *pGPIO = GPIO_GetPointer(portNum);

	if (pGPIO != NULL) {
		pGPIO->FIOCLR |= bitValue;
	}
}


 

/*********************************************************************//**
 * @brief		Set Value for bits that have output direction on GPIO port.
 * @param[in]	portNum		Port number value, should be in range from 0 to 4
 * @param[in]	bitValue	Value that contains all bits on GPIO to set,
 * 							in range from 0 to 0xFFFFFFFF.
 * 							example: value 0x5 to set bit 0 and bit 1.
 * @return		None
 *
 * Note:
 * - For all bits that has been set as input direction, this function will
 * not effect.
 * - For all remaining bits that are not activated in bitValue (value '0')
 * will not be effected by this function.
 **********************************************************************/
void GPIO_SetValue(uint8_t portNum, uint32_t bitValue)
{
	LPC_GPIO_TypeDef *pGPIO = GPIO_GetPointer(portNum);

	if (pGPIO != NULL) {
		pGPIO->FIOSET |= bitValue;
	}
}


 

void GPIO_SetDir(uint8_t portNum, uint32_t bitValue, uint8_t dir)
{
	LPC_GPIO_TypeDef *pGPIO = GPIO_GetPointer(portNum);

	if (pGPIO != NULL) {
		// Enable Output
		if (dir) {
			pGPIO->FIODIR |= bitValue;
		}
		// Enable Input
		else {
			pGPIO->FIODIR &= ~bitValue;
		}
	}
}


 

void FIO_SetMask(uint8_t portNum, uint32_t bitValue, uint8_t maskValue)
{
	LPC_GPIO_TypeDef *pFIO = GPIO_GetPointer(portNum);
	if(pFIO != NULL) {
		// Mask
		if (maskValue){
			pFIO->FIOMASK |= bitValue;
		}
		// Un-mask
		else {
			pFIO->FIOMASK &= ~bitValue;
		}
	}
}


 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值