|
请问,我在使用V5开发板测试LED灯的时候,读取LED3的状态是否亮灭,使用函数 bsp_IsLedOn(3) 不能正确读取,使用 HAL_GPIO_ReadPin(GPIOF,GPIO_PIN_8) 函数就可以回读到正常的0或1。
/******************************************
bsp_LedOn(3); //高电平
//bsp_LedOff(3);//低电平
bsp_DelayMS(100);
bsp_IsLedOn(3);
printf("\n\r");
printf("LED3的状态 = %d\n\r", bsp_IsLedOn(3));
HAL_GPIO_ReadPin(GPIOF,GPIO_PIN_8);
printf("\n\r");
printf("GPIO_PIN_8状态 = %d\n\r", HAL_GPIO_ReadPin(GPIOF,GPIO_PIN_8));
*****************************************/
以上是我在mian函数的写法,一下是我串口打印信息
/***********************
LED3的状态 = 0
GPIO_PIN_8状态 = 1
**********************/
然后我在看 bsp_IsLedOn()函数原型是如下
/********************************************
uint8_t bsp_IsLedOn(uint8_t _no)
{
if (_no == 1)
{
if ((GPIO_PORT_LED1->ODR & GPIO_PIN_LED1) == 1)
{
return 1;
}
return 0;
}
else if (_no == 2)
{
if ((GPIO_PORT_LED2->ODR & GPIO_PIN_LED2) == 1)
{
return 1;
}
return 0;
}
else if (_no == 3)
{
if ( (GPIO_PORT_LED3->ODR & GPIO_PIN_LED3) == 1)
{
return 1;
}
return 0;
}
else if (_no == 4)
{
if ((GPIO_PORT_LED4->ODR & GPIO_PIN_LED4) == 1)
{
return 1;
}
return 0;
}
return 0;
}
************************************************************/
然后我把函数判断改成
if ( (GPIO_PORT_LED3->ODR & GPIO_PIN_LED3) != 0)
{
return 1;
}
return 0;
}
后即可判断正常
串口打印信息如下:
LED3的状态 = 1
GPIO_PIN_8状态 = 1
目前就是不知道哪里出现了问题, ”!=0“ 跟 “ == 1 ” 的问题吗
|
|