欧美极品高清xxxxhd,国产日产欧美最新,无码AV国产东京热AV无码,国产精品人与动性XXX,国产传媒亚洲综合一区二区,四库影院永久国产精品,毛片免费免费高清视频,福利所导航夜趣136

標(biāo)題: 按鍵鍵盤(pán)加數(shù)碼管顯示 [打印本頁(yè)]

作者: marineZty    時(shí)間: 2017-5-24 15:01
標(biāo)題: 按鍵鍵盤(pán)加數(shù)碼管顯示
#include<reg52.h>

#define uchar unsigned char
#define uint unsigned int

uchar data dir_buf; //顯示緩沖區(qū)
uchar key;           //計(jì)算所得到的鍵值
uchar i2;  //鍵號(hào)

//code uchar dirtab[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e};//顯示代碼表
code uchar dirtab[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
code uchar keytab[]={0xee,0xed,0xeb,0xe7,0xde,0xdd,0xdb,0xd7,0xbe,0xbd,0xbb,0xb7,0x7e,0x7d,0x7b,0x77};//顯示鍵值表

void delay(uint); //延時(shí)函數(shù)
void display();        //顯示函數(shù)
void keyscan();          //鍵盤(pán)掃描函數(shù)

void main()
{
//i2=16;
//dir_buf=16;
while(1)
{
  keyscan();
  dir_buf=i2;
  display();
}
}

void delay(uint x)
{
uint t1,t2;
for(t1=0;t1<x;t1++)
   for(t2=0;t2<120;t2++);

}

void display()
{
   if(i2>9)
   {
   P0=dirtab[1];
   P3=dirtab[dir_buf-10];
   }
   else
   {
   P0=dirtab[0];
   P3=dirtab[dir_buf];
   }

}



void keyscan()
{
uchar code_l,code_h,i1;
P1=0xf0;
code_l=P1;
code_l=code_l&0xf0;
if(code_l!=0xf0)
{
  delay(6);
   code_l=P1;
   code_l=code_l&0xf0;
   if(code_l!=0xf0)
   {
    code_h=0xfe;
        for(i1=0;i1<4;i1++)
        {
         P1=code_h;
         code_l=P1;
     code_l=code_l&0xf0;
     if(code_l==0xf0)
         {
          code_h=(code_h<<1)|0x01;
         }
         else break;
        }
        P1=0xff;
        while(P1!=0xff);
        code_h=code_h&0x0f;
        key=code_h+code_l;
        for(i2=0;i2<16;i2++)
        {
         if(key==keytab[i2])
         {
           break;
         }
        }
   }
}

}






歡迎光臨 (http://www.raoushi.com/bbs/) Powered by Discuz! X3.1