|
獨立按鍵單用可以,兩個一起用就不行了???
我這代碼是邏輯有問題嗎???
獨立按鍵默認接上拉電阻高電平,按下低電平
//全局變量
u8 start1=1;
u8 start2=1;
//按鍵檢測函數(shù)
void keypros()
{
while(k1==1) //開始正轉(zhuǎn)
{
delay(1000);
if(k1==1)
{
start1=0;
}
delay(1000);
while(!k1);//(不能要)
}
while(k2==1) //開始反轉(zhuǎn)
{
delay(1000);
if(k2==1)
{
start2=0;
}
delay(1000);
while(!k2);
}
}
void main()
{
P1=0X00;
while(1)
{
keypros();
if(start1==0)
{
dianjizhengzhuan();
}
if(start2==0)
{
dianjifanzhuan();
}
}
}
|
|