[mw_shl_code=c,true] t=KEY_Scan (0);
if(t)
{
switch(t)
{
case KEY_UP: //按上蜂鸣器响且红灯亮
PBout(8) =1;
for(i=50000;i>0;i--)
for(j=50;j>0;j--);
PBout (8)=0;
GPIO_ResetBits (GPIOE,GPIO_Pin_5); //这里的pe5口下到板子上是控制绿灯[/mw_shl_code]
[mw_shl_code=c,true] for(i=50000;i>0;i--)
for(j=50;j>0;j--);
GPIO_SetBits (GPIOE,GPIO_Pin_5);
break;
case KEY_RIGHT: //按左红灯亮
GPIO_ResetBits (GPIOE,GPIO_Pin_5); //而这里的pe5口下到板子上却是控制红灯 for(i=50000;i>0;i--)
for(j=50;j>0;j--);
GPIO_SetBits (GPIOE,GPIO_Pin_5);
break;
case KEY_LEFT: //按右绿灯亮
GPIO_ResetBits (GPIOB,GPIO_Pin_5);
for(i=50000;i>0;i--)
for(j=50;j>0;j--);
GPIO_SetBits (GPIOB,GPIO_Pin_5);
break;
case KEY_DOWN: //按下红绿灯亮蜂鸣器响
GPIO_ResetBits (GPIOB,GPIO_Pin_5);
GPIO_ResetBits (GPIOE,GPIO_Pin_5);
PBout(8) =1;
for(i=50000;i>0;i--)
for(j=50;j>0;j--);
GPIO_SetBits (GPIOB,GPIO_Pin_5);
GPIO_SetBits (GPIOE,GPIO_Pin_5);
PBout (8)=0;
break;
}
}else delay_ms(10);
}[/mw_shl_code]
[mw_shl_code=c,true]这是我根据按键实验改的一个实验,设计的是按上键时红灯亮,可下到板子上却是绿灯亮这是为什么?按原理图的话pe5口是红灯,可是为什么前后完全一样的代码控制的却不是一个灯呢?[/mw_shl_code]
|