www.pudn.com > GKC-DProteus.rar > key.h, change:2008-09-11,size:1237b


/* 
*                                                * 
*    File       : keyscan.c                      * 
*    Date       : 2006-11-5                      * 
*    Version    : 1.0                            * 
*                                                * 
************************************************** 
*    Description:                                * 
*                按键扫描程序                    * 
*    (P1口:低四位对应键盘行线,高四位对应键盘列线*  
*         4乘4的矩阵键盘中,基本识别程序         * 
*                                                * 
*************************************************/ 
 
#include <reg52.h> 
#include<intrins.h> 
#include<absacc.h> 
#define uchar unsigned char 
#define uint  unsigned int 
void delay_ms(uint); 
 
uchar keypressed() 
{ 
  uchar key; 
  key=P1|0xf0; 
  if(key==0xff) 
     return 0; 
  else 
     return 1; 
} 
uchar keyscan(void) 
{ 
  uchar key=0; 
  delay_ms(10); 
  if(keypressed()==1) 
  { 
  key=P1|0xf0; 
  if(key==0xfe) 
    { key=1;} 
  else  if(key==0xfb) 
    { key=2;} 
  else if(key==0xf7) 
    { key=3;} 
  else if(key==0xfd) 
    { key=4;}   
  else 
    { key=0;} 
  do{ 
     }while((keypressed())==1); 
  delay_ms(10); 
  } 
  return key; 
 }