www.pudn.com > STC.rar > Stc12C5A32ButtonP4.c, change:2009-08-25,size:578b


 
sfr P4   = 0xC0; 
sfr P4SW = 0xbb; 
 
#define EN_P4();	P4SW = 0X30;  //转换为IO口	 
  
sbit key1 = P4^4;  //右边按键 
sbit key2 = P4^5;  //左边按键 
 
void ButtonDelay()  //按键消抖,40ms 
{ 
	unsigned char a,b,c; 
	for(c=40;c>0;c--) 
	{ 
		for(b=59;b>0;b--) 
        for(a=45;a>0;a--); 
	} 
} 
 
unsigned char get_keyval() 
{ 
	unsigned char k; 
	if(key1 == 0 || key2 == 0 ) 
	{ 
		ButtonDelay(); 
		if(key1 == 0 || key2 == 0 ) 
		{ 
			if(key1 == 0)	k = 1; 
			if(key2 == 0)   k = 2; 
			while(key1 == 0 || key2 == 0) ; 
			return k; 
		} 
		return 0; 
	} 
	return 0; 
}