嵌入式——独立键盘扫描
#include <reg51.h> #define IO_KEY P1 void Delay(unsigned int c); unsigned char KeyScan(); void main(){ unsigned char key = 0; while(1){ key = KeyScan(); Delay(100); } } void Delay(unsigned int c){ unsigned char a,b; for(;c>0;c--) for(b=13;b>0;b--) for(a=38;a>0;a--); } unsigned char KeyScan(){ unsigned char key = 0; if(IO_KEY != 0xff){ Delay(10); //延时10ms,消除抖动 if(IO_KEY != 0xff){ key = IO_KEY; } } return key; }