www.pudn.com > HT1621Control.rar > kbd_drv.c


/*C************************************************************************** 
* NAME:         kbd_drv.c 
*---------------------------------------------------------------------------- 
* Copyright (c) 2006 Atmel. 
*---------------------------------------------------------------------------- 
* RELEASE:      C51 Sample       
* REVISION:     1.00      
*---------------------------------------------------------------------------- 
* 
*****************************************************************************/ 
#include "system\reg51.h" 
#include "system\compiler.h" 
#include "system\config.h" 
#include "driver\kbd_drv.h"                      /* scheduler definition */ 
 
/*F************************************************************************** 
* NAME: kbd_init 
*---------------------------------------------------------------------------- 
* PARAMS: 
* 
* return: 
*---------------------------------------------------------------------------- 
* PURPOSE:  
*   Keyboard initialisation function 
*---------------------------------------------------------------------------- 
* EXAMPLE: 
*---------------------------------------------------------------------------- 
* NOTE: 
*---------------------------------------------------------------------------- 
* REQUIREMENTS: 
* ram/xram: 
* cycle: 
* stack:  
* code: 
*****************************************************************************/ 
void kbd_init (void) 
{ 
	P1 = P1|0x1f; 
} 
 
/*F************************************************************************** 
* NAME: kbd_decode 
*---------------------------------------------------------------------------- 
* PARAMS: 
* 
* return: 
*   Decoded key pressed 
*---------------------------------------------------------------------------- 
* PURPOSE:  
*   Decode the key that generated an IT 
*---------------------------------------------------------------------------- 
* EXAMPLE: 
*---------------------------------------------------------------------------- 
* NOTE: 
*---------------------------------------------------------------------------- 
* REQUIREMENTS: 
* ram/xram: 
* cycle: 
* stack:  
* code: 
*****************************************************************************/ 
/*¶Á¼üÅ̼üÖµ³ÌÐò¶Î*/ 
Byte kbd_decode (void) 
{ 
	Byte key=0; 
	 
	key = P1&0x1f; 
	if (key != 0x1f) { key_flag = High; return(key);} 
	else{ 
		P1_0 = Low; 
		key = P1&0x1e; 
		if (key != 0x1e) { key_flag = High; return(key);} 
		else{ 
			P1_0 = High; 
			P1_1 = Low; 
			key = P1&0x1d; 
			if (key != 0x1d) { key_flag = High; return(key);} 
			else{ 
				P1_1 = High; 
				P1_2 = Low; 
				key = P1&0x1b; 
				if (key != 0x1b) { key_flag = High; return(key);} 
				else{ 
					P1_2 = High; 
					P1_3 = Low; 
					key = P1&0x17; 
					if (key != 0x17) { key_flag = High; return(key);} 
					else{ 
						 P1_3 = High; 
						 key_flag = Low; /* Have not key process */ 
						 return(0x00); 
					} 
				} 
			} 
		} 
	} 
}