导航: 老古网老古论坛XMOS公共讨论区XMOS开源项目区单片机程序设计嵌入式系统广告区域
→大家看看这个程序,可否解释一下

* 41421: 关于复合键盘的程序编写,肯请高手高见

   月如镜 
月如镜发表的帖子 

 大家看看这个程序,可否解释一下
#include   <reg51.h>  
sbit PinScanKey1=P1^4;
sbit PinScanKey2=P1^5;
sbit PinScanKey3=P1^6;
sbit PinScanKey4=P0^4;
sbit PinScanKey5=P0^3;
#define TRUE 1
#define FALSE 0
#define DELAY_value 5
unsigned char a[8];
unsigned char bdata count;
sbit count0=count^0;
sbit count1=count^1;
sbit count2=count^2;
sbit p2_4=P2^4;
sbit p0_6=P0^6;
sbit p0_5=P0^5;
code unsigned char tb[31]={0xfc,0x60,0xda,0xf2,0x66,0xb6,0xbe,0xe0,0xfe,0xf6,0xee,0x3e,0x9c,0x7a,0x9e,0x8e,0x2e,0x1c,0x72,0x2a,0x3a,0xce,0x7c,0x00,0x10,0x80,0x02,0x82,0x1e,0x12,0x92};
/* ?0,1,2,3,4,5,6,7,8,9,a,b,c,d,e,f,h,l,j,n,o,p,u,dark,low-,high-,mid-,high=,t,low=,三?``
*/


void delay(short i);
void keyinit(void);
unsigned char keyscan(void);

void coms() interrupt 1
 { TH0=0xf8;
   TL0=30;
   SBUF=tb[a[count]];
   p2_4=count0;
   p0_6=count1;
   p0_5=count2;
   while(TI) {
   TI=0; }
   if(count  <7)count++;
   else count=0;
  }

 void sinit(void)
 {SCON=0;
 TMOD=1;
 TH0=0x80;
 TL0=0x20;
 TR0=1;
 EA=1;
 ET0=1;
 TI=0;
 }

void keyinit(void)
{PinScanKey1=1;
 PinScanKey2=1;
 PinScanKey3=1;
 PinScanKey4=1;
 PinScanKey5=1;
}


void delay(short i)
{
   int k=0;
   k=i*DELAY_value;
   while(k--);
}

unsigned char keyscan()
{ if((PinScanKey1==FALSE)&&(PinScanKey2==FALSE))
         {delay(DELAY_value);
              if((PinScanKey1==FALSE)&&(PinScanKey2==FALSE))
                  {delay(DELAY_value);
                      if((PinScanKey1==FALSE)&&(PinScanKey2==FALSE))
                                return 6;}
         }
   if((PinScanKey1==FALSE)&&(PinScanKey3==FALSE))
         {delay(DELAY_value);
               if((PinScanKey1==FALSE)&&(PinScanKey3==FALSE))
                        {delay(DELAY_value);
                              if((PinScanKey1==FALSE)&&(PinScanKey3==FALSE))
                                   return 7;}
          }


   if(PinScanKey1==FALSE)
        {delay(DELAY_value);
           if(PinScanKey1==FALSE)
               {delay(DELAY_value);
                  if(PinScanKey1==FALSE)
                        return 1;}
         }

   if(PinScanKey2==FALSE)
          {delay(DELAY_value);
              if(PinScanKey2==FALSE)
                  {delay(DELAY_value);
                     if(PinScanKey2==FALSE)
                          return 2;}
           }

   if(PinScanKey3==FALSE)
        {delay(DELAY_value);
            if(PinScanKey3==FALSE)
                {delay(DELAY_value);
                   if(PinScanKey3==FALSE)
                       return 3;}
         }

  if(PinScanKey4==FALSE)
     {delay(DELAY_value);
           if(PinScanKey4==FALSE)
              {delay(DELAY_value);
                 if(PinScanKey4==FALSE)
                         return 4;}
     }


   if(PinScanKey5==FALSE)
       {delay(DELAY_value);
          if(PinScanKey5==FALSE)
              {delay(DELAY_value);
                  if(PinScanKey5==FALSE)
                      return 5;}
            }

   else return(a[7]);


   }
void main(void)
{
   sinit();
    do
   {keyinit();
   a[7]=keyscan();
   }while(1);
 }
这个程序是按键后,从数码管显示出来,比如按了1键,会显示1,按5会显示5,按1和2会显示6,按1和3会显示7,但是有一点,就是在按1到4这四个键时,没有问题,不按键时,数码管继续显示,但是5和6,7的话,松开手后立即就不显示了,请问谁能帮我解释一下。

发表时间:2003年9月3日22:39:54

  
回复该帖

本主题共有 10 帖,分页:>>>>>该主题的所有内容[10]条

 *树形目录 只列出部分跟帖的标题以及简单的摘要信息 该主题的部分跟帖如下:

  41472.[详细]编码键盘?
摘要:......(无内容)
- [guantingwei][874次] 2003年9月4日

  41483.[详细]请问如何在一个程序里调用2个定时中断,一显示,一键盘。
摘要:[quote][b]以下是引用[i]guantingwei在2003-9-4 20:35:29[/i]的发言:[/b] 编码键盘? [/quote]   不知,这样的程序该怎么初始......(125字)
- [月如镜][847次] 2003年9月4日

  41537.[详细]怎么个两个定时中断?请详讲。
摘要:是有两个定时器,在其分别的中断服务程序中一个进行显示一个进行键盘查询?(这样可以先分别进行参数设置,最后同时开中断)还是怎么的。其实可以用专用的键盘显示芯片如7289,7189,这样可以免去很多麻烦的啊。   ......(459字)
- [guantingwei][917次] 2003年9月5日

[上一篇帖子]:大侠帮我解释一下while和if的区别,看这个例子。do   {whil
[下一篇帖子]:"NSG N62C64S-70LL 063647"请问是什么