文章编号:668 .4777

『关闭窗口』

两个c程序(dhd0)


#include "reg51.h"
#define uchar unsigned char
#define uint unsigned int
void d1ms(void);
uchar kbscan(void);

void main(void)
{
uchar key;
while(1)
{
key=kbscan();
d1ms();
}
}

void d1ms(void)
{
uchar i;
for(i=200;i>0;i--) {}
}

uchar kbscan(void)
{
uchar sccode,recode;
P1=0xf0;
if((P1&0xf0)!=0xf0)
{
  d1ms();
  if((P1&0xf0)!=0xf0)
   {
    sccode=0xfe;
    while((sccode&0x10)!=0)
    {
     P1=sccode;
     if((P1&0xf0)!=0xf0)
      {
       recode=(P1&0xf0)|0x0f;
       return((~sccode)+(~recode));
      }
     else sccode=(sccode<<1)|0x01;
    }
   }
  }
return(0);
}

         


#include<reg52.h>
#include<intrins.h>
#include<absacc.h>

#define uchar unsigned char
#define uint  unsigned int


keyscan()
{
  uchar i,h=0xfe;
  for(i=4,P1=h;i>0;i--)
  {
    if((P1&0xf0)!=0xf0)
    {
      uchar a;
      for(a=255;a>0;a--)
      {}
      if((P1&0xf0)!=0xf0)
      {
        uchar key,p;
        p=P1;
        for(key=0;key<16;key++)
        {
          uchar code keytab[]={0xEE,0xDE,0xBE,0x7E,
                   0xED,0xDD,0xBD,0x7D,
                   0xEB,0xDB,0xBB,0x7B,
                   0xE7,0xD7,0xB7,0x77};
          if(p==keytab[key])
          {
            P1=0xff;
            return(key);
          }
        }
      }
      
    }
   h=_crol_(h,1);
   P1=h;
  }
P1=0xff;
return(16);
}


main()
{  while(1)
  {P0=keyscan();
   while(1)
   ;
  }
}



(文章推荐人:电池)

 

返回大虾论坛 返回首页