Demo entry 6657754

C

   

Submitted by A on Nov 04, 2017 at 16:06
Language: C. Code size: 1.3 kB.

unsigned char Key_Scan()
{
	unsigned char curKeyValue = NO_KEY_PRESS;           	
	static unsigned char keyValueBackup = NO_KEY_PRESS;	
	static unsigned int keyPressTimer = 0;              
	static unsigned int keyQuickTimer = 0;				
	static unsigned char curStatus = KEY_STATUS_noKeyPress; 
	unsigned char returnKeyValue;
	/*-------获得按键值---------*/
	curKeyValue = Get_KeyValue();		

	switch(curStatus) {
		
		case KEY_STATUS_noKeyPress: 						//没有按键的状态
			if( curKeyValue != NO_KEY_PRESS ) {
				keyValueBackup = curKeyValue;
				curStatus = KEY_STATUS_filter; 					
			}
			returnKeyValue = NO_KEY_PRESS;
			break;
		
		case KEY_STATUS_filter:								//软件消抖过程
			if( ++keyPressTimer > KEY_FILTER_TIME ) {	
				returnKeyValue = keyValueBackup; 
				curStatus = KEY_STATUS_clicking; 				
			}
			else
				returnKeyValue = NO_KEY_PRESS;
			break;
		
		case KEY_STATUS_clicking: 							//按键按下状态
			if( curKeyValue == NO_KEY_PRESS )
				curStatus = KEY_STATUS_Release; 
			returnKeyValue = NO_KEY_PRESS; 
			break;
			
		case KEY_STATUS_Release:							//释放按键状态
			keyValueBackup = NO_KEY_PRESS;
			keyPressTimer = 0;
			keyQuickTimer =0;
			curStatus = KEY_STATUS_noKeyPress;			
			break;	
		
		default:
			break;
	}
	return returnKeyValue;	
}

This snippet took 0.00 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).