|
使用光敏电阻的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 ucPinValue
GPIO_IF_GetPortNPin(GPIOIN,&uiGPIOPort,&pucGPIOPin);
ucPinValue = GPIO_IF_Get(GPIOIN,uiGPIOPort,pucGPIOPin);
console.log(ucPinValue);
//LIGHT slow
if(ucPinValue == 1)
{
GPIO_IF_LedOn(MCU_RED_LED_GPIO);
}
//light high
else
{
GPIO_IF_LedOff(MCU_RED_LED_GPIO);
}
//Enable GPIO Interrupt
MAP_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 设置中断向量表基址,允许中断,初始化MCU
BoardInit();
// 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;
}
谢谢啦~
|
|