使用光敏电阻的DO 输出高低电平,借助GPIO的input读取电平值,控制小灯亮暗。 但是,始终得不出想要的现象,而且,明明在初始时将所有灯都关闭了,但是,他依旧是亮的, 下面是代码
//control the input void ReadDeviceConfiguration() {unsigned int uiGPIOPort;unsigned char pucGPIOPin;unsigned char ucPinValue;GPIO_IF_LedOff(MCU_ALL_LED_IND);while(1){//Read PIN1 ucPinValueGPIO_IF_GetPortNPin(GPIOIN,&uiGPIOPort,&pucGPIOPin);ucPinValue = GPIO_IF_Get(GPIOIN,uiGPIOPort,pucGPIOPin);console.log(ucPinValue);//LIGHT slowif(ucPinValue == 1){GPIO_IF_LedOn(MCU_RED_LED_GPIO);}//light highelse{GPIO_IF_LedOff(MCU_RED_LED_GPIO);}//Enable GPIO InterruptMAP_GPIOIntClear(GPIOA0_BASE,GPIO_PIN_7);MAP_IntPendClear(INT_GPIOA0);MAP_IntEnable(INT_GPIOA0);MAP_GPIOIntEnable(GPIOA0_BASE,GPIO_PIN_7);ucPinValue=0;}} int main() {//set vector table base 设置中断向量表基址,允许中断,初始化MCUBoardInit();// Power on the corresponding GPIO port B for 9,10,11.// Set up the GPIO lines to mode 0 (GPIO)PinMuxConfig();GPIO_IF_LedConfigure(LED1|LED2|LED3);GPIO_IF_LedOff(MCU_ALL_LED_IND);ReadDeviceConfiguration();return 0; }
谢谢啦~
Alvin Chen:
你测一下你的IO的输出电平高低,以及你的那个LED的电路是要给高电平亮还是低电平亮。
GPIO 参照:
blog.csdn.net/…/87011439
user5984440:
回复 Alvin Chen:
好嘞,谢谢啦~