|
#include <REGX51.H>
#include "Delay.h"
#include "KEY.h"
void main()
{
// if(Key()==2)
// {
// P2_0=0;
//
// }
// if(Key()==1)
// {
// P2_0=1;
//
// }
if(P3_1==0)
{
Delay(20);
while(P3_1==0);
Delay(20);
P2_0=0;
}
if(P3_0==0)
{
Delay(20);
while(P3_0==0);
Delay(20);
P2_0=1;
}
}
我注釋掉的代碼使用時按鍵不靈敏,
沒有注釋的代碼使用下來是沒有問題的
KEY()函數(shù)里面的代碼
#include <REGX51.H>
#include "Delay.h"
unsigned char Key()
{
unsigned char KeyNumber=0;
if(P3_1==0){Delay(20);while(P3_1==0);Delay(20);KeyNumber=1;}
if(P3_0==0){Delay(20);while(P3_0==0);Delay(20);KeyNumber=2;}
if(P3_2==0){Delay(20);while(P3_2==0);Delay(20);KeyNumber=3;}
if(P3_3==0){Delay(20);while(P3_3==0);Delay(20);KeyNumber=4;}
return KeyNumber;
}
求求大佬能不能幫忙看下,萬分感謝,剛學(xué)沒多久
|
|