完整代码:
#include <LPC21xx.H>`
#define S1 0x20
#define LED0_bm 0x10000
#define LED1_bm 0x20000
#define LED2_bm 0x40000
#define LED3_bm 0x80000
int uiReadButton1(){
unsigned int uiReturnNumber = 0;
uiReturnNumber = ((IO0PIN&S1)== S1) ? 1: 0;
return uiReturnNumber;
}
void LedOn(unsigned int uiNumberOfLed){
switch(uiNumberOfLed){
case 0:
IO1SET = IO1SET|LED0_bm;
break;
case 1:
IO1SET = IO1SET|LED1_bm;
break;
}
}
int main(){
int iPress;
IO1DIR = IO1DIR|LED0_bm|LED1_bm;
IO0DIR = IO0DIR|S1;
IO0SET = IO0SET|S1;
iPress = uiReadButton1();
LedOn(iPress);
}
在教程中,有人说如果按下按钮-相应的PIN的逻辑为0,而未按下时PIN的逻辑为1。
好,所以我配置了输入方向:
IO0DIR = IO0DIR|S1;
我有类似的东西: debugging IO0DIR
接下来我用:
IO0SET = IO0SET|S1;
我的询问是-在这种情况下,按钮是按下还是未按下? 从逻辑上讲,应该取消该按钮,因为选中了该框,但是默认情况下,在使用IO0DIR之后,该按钮的另一侧是按下的。