1 //write by:cyt 2 //Time:2017-2-10 3 //Porject Name:key shake_destory 4 #include<reg51.h> 5 #define GPIO_KEY P0/// 6 void Delay1ms(unsigned char n); 7 unsigned char Key_Scan() // GPIO_KEY为全局变量,在这里作输入 8 { 9 unsigned char i=0,Key_Value=0; 10 if(GPIO_KEY!=0xff) 11 { 12 Delay1ms(10); 13 if(GPIO_KEY!=0xff) 14 Key_Value = GPIO_KEY; 15 while(GPIO_KEY!=0xff&&i<50) 16 { 17 Delay1ms(10); 18 i++; 19 } 20 } 21 return Key_Value; 22 }