关于作者

姓名:陈彬

性别:男

出生日期:1985-11-12

地区:中国-长沙

联系电话:13975852053

QQ:83286720婚否:保密
用户名:linux306
笔名:losthink
地区: 中国-长沙
行业:学生

日历  

快速登录

+ 用户名:
+ 密 码:

在线留言



访问统计:
文章个数:27
评论个数:5
留言条数:2




Powered by BlogDriver 2.1

梦幻开源程序小组

 

文章

行列4*4键盘驱动程序

/****************************************************************
*行列4*4键盘驱动程序
*作者:Eqianli studio
*日期:2006/11/2
*说明:main()主函数,delay()延时,keyscan()键盘扫描,PinLamp()点灯

****************************************************************/

/****************************************************************
/////////////////////Beginning of Program////////////////////////
****************************************************************/

#include"AT89X52.H"
#include"stdio.h"

#define TRUE             1
#define FALSE            0
#define DELAY_VALUE      3


#define PinDrvKey1     P1_0
#define PinDrvKey2     P1_1
#define PinDrvKey3     P1_2
#define PinDrvKey4     P1_3

#define PinScanKey1    P1_4
#define PinScanKey2    P1_5
#define PinScanKey3    P1_6
#define PinScanKey4    P1_7


#define Lamp           P2_0
          


void initial(void);
void delay(short i);
unsigned char keyscan(void);
void PinLamp(void);

void main(void)
  {
         unsigned char keyword;
            initial();
            while(1)
             {
           
           keyword=keyscan();
                  
             }
  }


void initial(void)
 {
       
          P2_0=TRUE;           //发光三极管高为不亮

  }


void PinLamp(void)

    {
 
  
          Lamp=FALSE;
       delay(DELAY_VALUE);
             delay(DELAY_VALUE);
              delay(DELAY_VALUE);
               delay(DELAY_VALUE);
                 delay(DELAY_VALUE); 
                           Lamp=TRUE;
        
  }


unsigned char keyscan(void)
  {      
       
          PinDrvKey1=FALSE;
          PinScanKey1=TRUE;
        if(PinScanKey1!=TRUE)
              PinLamp();
           delay(DELAY_VALUE);
    if(PinScanKey1!=TRUE)
             {
               delay(DELAY_VALUE);
             if(PinScanKey1!=TRUE)
         return 1; }
  
    PinScanKey2=TRUE;
        if(PinScanKey2!=TRUE)
              PinLamp();
           delay(DELAY_VALUE);
    if(PinScanKey2!=TRUE)
             {
               delay(DELAY_VALUE);
             if(PinScanKey2!=TRUE)
         return 4; }

     PinScanKey3=TRUE;
        if(PinScanKey3!=TRUE)
             PinLamp();
           delay(DELAY_VALUE);
    if(PinScanKey3!=TRUE)
             {
               delay(DELAY_VALUE);
             if(PinScanKey3!=TRUE)
         return 7; }

     PinScanKey4=TRUE;
        if(PinScanKey4!=TRUE)
              PinLamp();
           delay(DELAY_VALUE);
    if(PinScanKey4!=TRUE)
             {
               delay(DELAY_VALUE);
             if(PinScanKey4!=TRUE)
         return 10; }
                 PinDrvKey1=TRUE;       //扫描完一列


      PinDrvKey2=FALSE;
          PinScanKey1=TRUE;
        if(PinScanKey1!=TRUE)
             PinLamp();
           delay(DELAY_VALUE);
    if(PinScanKey1!=TRUE)
             {
               delay(DELAY_VALUE);
             if(PinScanKey1!=TRUE)
         return 2; }
  
    PinScanKey2=TRUE;
        if(PinScanKey2!=TRUE)
             PinLamp();
           delay(DELAY_VALUE);
    if(PinScanKey2!=TRUE)
             {
               delay(DELAY_VALUE);
             if(PinScanKey2!=TRUE)
         return 5; }

     PinScanKey3=TRUE;
        if(PinScanKey3!=TRUE)
             PinLamp();
           delay(DELAY_VALUE);
    if(PinScanKey3!=TRUE)
             {
               delay(DELAY_VALUE);
             if(PinScanKey3!=TRUE)
         return 8; }

     PinScanKey4=TRUE;
        if(PinScanKey4!=TRUE)
              PinLamp();
           delay(DELAY_VALUE);
    if(PinScanKey4!=TRUE)
             {
               delay(DELAY_VALUE);
             if(PinScanKey4!=TRUE)
         return 11; }
                 PinDrvKey2=TRUE;       //扫描完二列

    PinDrvKey3=FALSE;
          PinScanKey1=TRUE;
        if(PinScanKey1!=TRUE)
              PinLamp();
           delay(DELAY_VALUE);
    if(PinScanKey1!=TRUE)
             {
               delay(DELAY_VALUE);
             if(PinScanKey1!=TRUE)
         return 3; }
  
    PinScanKey2=TRUE;
        if(PinScanKey2!=TRUE)
             PinLamp();
           delay(DELAY_VALUE);
    if(PinScanKey2!=TRUE)
             {
               delay(DELAY_VALUE);
             if(PinScanKey2!=TRUE)
         return 6; }

     PinScanKey3=TRUE;
        if(PinScanKey3!=TRUE)
             PinLamp();
           delay(DELAY_VALUE);
    if(PinScanKey3!=TRUE)
             {
               delay(DELAY_VALUE);
             if(PinScanKey3!=TRUE)
         return 9; }

     PinScanKey4=TRUE;
        if(PinScanKey4!=TRUE)
              PinLamp();
           delay(DELAY_VALUE);
    if(PinScanKey4!=TRUE)
             {
               delay(DELAY_VALUE);
             if(PinScanKey4!=TRUE)
         return 12; }
                 PinDrvKey3=TRUE;       //扫描完三列

    PinDrvKey4=FALSE;
          PinScanKey1=TRUE;
        if(PinScanKey1!=TRUE)
             PinLamp();
           delay(DELAY_VALUE);
    if(PinScanKey1!=TRUE)
             {
               delay(DELAY_VALUE);
             if(PinScanKey1!=TRUE)
         return 13; }
  
    PinScanKey2=TRUE;
        if(PinScanKey2!=TRUE)
               PinLamp();
           delay(DELAY_VALUE);
    if(PinScanKey2!=TRUE)
             {
               delay(DELAY_VALUE);
             if(PinScanKey2!=TRUE)
         return 14; }

     PinScanKey3=TRUE;
        if(PinScanKey3!=TRUE)
              PinLamp();
           delay(DELAY_VALUE);
    if(PinScanKey3!=TRUE)
             {
               delay(DELAY_VALUE);
             if(PinScanKey3!=TRUE)
         return 15; }

     PinScanKey4=TRUE;
        if(PinScanKey4!=TRUE)
              PinLamp();
           delay(DELAY_VALUE);
    if(PinScanKey4!=TRUE)
             {
               delay(DELAY_VALUE);
             if(PinScanKey4!=TRUE)
         return 16; }
                 PinDrvKey4=TRUE;       //扫描完四列

  }


void delay(short i)
  {
      int j=0;
  int k=0;
  k=i*DELAY_VALUE;
  while(j  j++; 
  }

- 作者: losthink 2006年11月16日, 星期四 21:25  回复(0) |  引用(0) 加入博采