www.pudn.com > RL78_G14-Demo.rar > keyboard.c, change:2013-04-25,size:1019b


#include "keyboard.h" 
/*this function is used to delay some time in scanning keyboard ,not good*/ 
void delay(uchar t) 
{ 
  for(;t>0;t--); 
  for(;t>0;t--);  /*delay some time,not sure*/ 
} 
/*this function is used to scan which button is pressed*/ 
int Keyboard_scan()    
{        
	int scan=0,key_v=0,temp=0; 
	for(;scan<4;scan++) 
	{ 
		P7|=0XFF; 
		P7&=~(1<<scan); 
	        temp=P7; 
		temp=temp&0xf0;   /*checking  higher four bits*/ 
		if(temp!=0xf0)    /*first check*/ 
		    { 
			  delay(100); /*delay some time*/ 
			  temp=P7; 
		          temp=temp&0xf0; 
			  if(temp!=0xf0) /*second check*/ 
			    {  
				 switch(temp) 
				 { 
				   case 0x70:{  key_v=1+(3-scan)*4; 
				   scan=4;} 
				   break; 
				   case 0xb0: { key_v=2+(3-scan)*4; 
				   scan=4;} 
				   break; 
				   case 0xd0:  {key_v=3+(3-scan)*4; 
				   scan=4;} 
				   break; 
			           case 0xe0: { key_v=4+(3-scan)*4; 
				   scan=4;} 
				   break; 
	             		} 
			    }  
		   } 
	     
	} 
	return key_v; 
}