<meter id="pryje"><nav id="pryje"><delect id="pryje"></delect></nav></meter>
          <label id="pryje"></label>

          新聞中心

          EEPW首頁 > 嵌入式系統(tǒng) > 設(shè)計應(yīng)用 > 4×4鍵盤及8位數(shù)碼管顯示構(gòu)成的電子密碼鎖

          4×4鍵盤及8位數(shù)碼管顯示構(gòu)成的電子密碼鎖

          作者: 時間:2008-10-15 來源:網(wǎng)絡(luò) 收藏
          實驗任務(wù)

          用4×4組成0-9數(shù)字鍵及確認(rèn)鍵。

          用8位數(shù)碼管組成顯示電路提示信息,當(dāng)輸入密碼時,只顯示“8.”,當(dāng)密碼位數(shù)輸入完畢按下確認(rèn)鍵時,對輸入的密碼與設(shè)定的密碼進(jìn)行比較,若密碼正確,則門開,此處用led發(fā)光二極管亮一秒鐘做為提示,同時發(fā)出“叮咚”聲;若密碼不正確,禁止按鍵輸入3秒,同時發(fā)出“嘀、嘀”報警聲;若在3秒之內(nèi)仍有按鍵按下,則禁止按鍵輸入3秒被重新禁止。

          2. 電路原理圖

          圖4.33.1

          3. 系統(tǒng)板上硬件連線

          (1). 把“系統(tǒng)”區(qū)域中的p0.0-p0.7用8芯排線連接到“動態(tài)數(shù)碼顯示”區(qū)域中的abcdefgh端子上。

          (2). 把“系統(tǒng)“區(qū)域中的p2.0-p2.7用8芯排線連接到“動態(tài)數(shù)碼顯示”區(qū)域中的s1s2s3s4s5s6s7s8端子上。

          (3). 把“系統(tǒng)”區(qū)域中的p3.0-p3.7用8芯排線連接到“4×4行列式鍵盤”區(qū)域中的r1r2r3r4c1c2c3c4端子上。

          (4). 把“單片機系統(tǒng)”區(qū)域中的p1.0用導(dǎo)線連接到“八路發(fā)光二極管模塊”區(qū)域中的l2端子上。

          (5). 把“單片機系統(tǒng)”區(qū)域中的p1.7用導(dǎo)線連接到“音頻放大模塊”區(qū)域中的spk in端子上。

          (6). 把“音頻放大模塊”區(qū)域中的spk out接到喇叭上。

          4. 程序設(shè)計內(nèi)容

          (1). 4×4行列式鍵盤識別技術(shù):有關(guān)這方面內(nèi)容前面已經(jīng)討論過,這里不再重復(fù)。

          (2). 8位數(shù)碼顯示,初始化時,顯示“p   ”,接著輸入最大6位數(shù)的密碼,當(dāng)密碼輸入完后,按下確認(rèn)鍵,進(jìn)行密碼比較,然后給出相應(yīng)的信息。在輸入密碼過程中,顯示器只顯示“8.”。當(dāng)數(shù)字輸入超過6個時,給出報警信息。在密碼輸入過程中,若輸入錯誤,可以利用“del”鍵刪除剛才輸入的錯誤的數(shù)字。

          (3). 4×4行列式鍵盤的按鍵功能分布圖如圖4.33.2所示:

           

           

           

          圖4.33.2

           

          5. c語言源程序
          #include at89x52.h>
           
          unsigned char ps[]={1,2,3,4,5};
           
          unsigned char code dispbit[]={0xfe,0xfd,0xfb,0xf7,
          0xef,0xdf,0xbf,0x7f};
          unsigned char code dispcode[]={0x3f,0x06,0x5b,0x4f,0x66,
          0x6d,0x7d,0x07,0x7f,0x6f,
          0x77,0x7c,0x39,0x5e,0x79,0x71,
          0x00,0x40,0x73,0xff};
          unsigned char dispbuf[8]={18,16,16,16,16,16,16,16};
          unsigned char dispcount;
          unsigned char flashcount;
          unsigned char temp;
          unsigned char key;
          unsigned char keycount;
          unsigned char pslen=5;
          unsigned char getps[6];
          bit keyoverflag;
          bit errorflag;
          bit rightflag;
          unsigned int second3;
          unsigned int aa,bb;
          unsigned int cc;
          bit okflag;
          bit alarmflag;
          bit hibitflag;
          unsigned char oka,okb;
           
          void main(void)
          {
          unsigned char i,j;
           
          tmod=0x01;
          th0=(65536-500)/256;
          tl0=(65536-500)%256;
          tr0=1;
          et0=1;
          ea=1;
           
          while(1)
          {
          p3=0xff;
          p3_4=0;
          temp=p3;
          temp=temp 0x0f;
          if (temp!=0x0f)
          {
          for(i=10;i>0;i--)
          for(j=248;j>0;j--);
          temp=p3;
          temp=temp 0x0f;
          if (temp!=0x0f)
          {
          temp=p3;
          temp=temp 0x0f;
          switch(temp)
          {
          case 0x0e:
          key=7;
          break;
          case 0x0d:
          key=8;
          break;
          case 0x0b:
          key=9;
          break;
          case 0x07:
          key=10;
          break;
          }
          temp=p3;
          p1_1=~p1_1;
          if((key>=0) (key10))
          {
          if(keycount6)
          {
          getps[keycount]=key;
          dispbuf[keycount+2]=19;
          }
          keycount++;
          if(keycount==6)
          {
          keycount=6;
          }
          else if(keycount>6)
          {
          keycount=6;
          keyoverflag=1;//key overflow
          }
          }
          else if(key==12)//delete key
          {
          if(keycount>0)
          {
          keycount--;
          getps[keycount]=0;
          dispbuf[keycount+2]=16;
          }
          else
          {
          keyoverflag=1;
          }
          }
          else if(key==15)//enter key
          {
          if(keycount!=pslen)
          {
          errorflag=1;
          rightflag=0;
          second3=0;
          }
          else
          {
          for(i=0;ikeycount;i++)
          {
          if(getps[i]!=ps[i])
          {
          i=keycount;
          errorflag=1;
          rightflag=0;
          second3=0;
          goto a;
          }
          }
          errorflag=0;
          rightflag=1;
          a: i=keycount;
          }
          }
          temp=temp 0x0f;
          while(temp!=0x0f)
          {
          temp=p3;
          temp=temp 0x0f;
          }
          keyoverflag=0;//?????????
          }
          }
          p3=0xff;
          p3_5=0;
          temp=p3;
          temp=temp 0x0f;
          if (temp!=0x0f)
          {
          for(i=10;i>0;i--)
          for(j=248;j>0;j--);
          temp=p3;
          temp=temp 0x0f;
          if (temp!=0x0f)
          {
          temp=p3;
          temp=temp 0x0f;
          switch(temp)
          {
          case 0x0e:
          key=4;
          break;
          case 0x0d:
          key=5;
          break;
          case 0x0b:
          key=6;
          break;
          case 0x07:
          key=11;
          break;
          }
          temp=p3;
          p1_1=~p1_1;
          if((key>=0) (key10))
          {
          if(keycount6)
          {
          getps[keycount]=key;
          dispbuf[keycount+2]=19;
          }
          keycount++;
          if(keycount==6)
          {
          keycount=6;
          }
          else if(keycount>6)
          {
          keycount=6;
          keyoverflag=1;//key overflow
          }
          }
          else if(key==12)//delete key
          {
          if(keycount>0)
          {
          keycount--;
          getps[keycount]=0;
          dispbuf[keycount+2]=16;
          }
          else
          {
          keyoverflag=1;
          }
          }
          else if(key==15)//enter key
          {
          if(keycount!=pslen)
          {
          errorflag=1;
          rightflag=0;
          second3=0;
          }
          else
          {
          for(i=0;ikeycount;i++)
          {
          if(getps[i]!=ps[i])
          {
          i=keycount;
          errorflag=1;
          rightflag=0;
          second3=0;
          goto a4;
          }
          }
          errorflag=0;
          rightflag=1;
          a4: i=keycount;
          }
          }
          temp=temp 0x0f;
          while(temp!=0x0f)
          {
          temp=p3;
          temp=temp 0x0f;
          }
          keyoverflag=0;//?????????
          }
          }
           
          p3=0xff;
          p3_6=0;
          temp=p3;
          temp=temp 0x0f;
          if (temp!=0x0f)
          {
          for(i=10;i>0;i--)
          for(j=248;j>0;j--);
          temp=p3;
          temp=temp 0x0f;
          if (temp!=0x0f)
          {
          temp=p3;
          temp=temp 0x0f;
          switch(temp)
          {
          case 0x0e:
          key=1;
          break;
          case 0x0d:
          key=2;
          break;
          case 0x0b:
          key=3;
          break;
          case 0x07:
          key=12;
          break;
          }
          temp=p3;
          p1_1=~p1_1;
          if((key>=0) (key10))
          {
          if(keycount6)
          {
          getps[keycount]=key;
          dispbuf[keycount+2]=19;
          }
          keycount++;
          if(keycount==6)
          {
          keycount=6;
          }
          else if(keycount>6)
          {
          keycount=6;
          keyoverflag=1;//key overflow
          }
          }
          else if(key==12)//delete key
          {
          if(keycount>0)
          {
          keycount--;
          getps[keycount]=0;
          dispbuf[keycount+2]=16;
          }
          else
          {
          keyoverflag=1;
          }
          }
          else if(key==15)//enter key
          {
          if(keycount!=pslen)
          {
          errorflag=1;
          rightflag=0;
          second3=0;
          }
          else
          {
          for(i=0;ikeycount;i++)
          {
          if(getps[i]!=ps[i])
          {
          i=keycount;
          errorflag=1;
          rightflag=0;
          second3=0;
          goto a3;
          }
          }
          errorflag=0;
          rightflag=1;
          a3: i=keycount;
          }
          }
          temp=temp 0x0f;
          while(temp!=0x0f)
          {
          temp=p3;
          temp=temp 0x0f;
          }
          keyoverflag=0;//?????????
          }
          }
           
          p3=0xff;
          p3_7=0;
          temp=p3;
          temp=temp 0x0f;
          if (temp!=0x0f)
          {
          for(i=10;i>0;i--)
          for(j=248;j>0;j--);
          temp=p3;
          temp=temp 0x0f;
          if (temp!=0x0f)
          {
          temp=p3;
          temp=temp 0x0f;
          switch(temp)
          {
          case 0x0e:
          key=0;
          break;
          case 0x0d:
          key=13;
          break;
          case 0x0b:
          key=14;
          break;
          case 0x07:
          key=15;
          break;
          }
          temp=p3;
          p1_1=~p1_1;
          if((key>=0) (key10))
          {
          if(keycount6)
          {
          getps[keycount]=key;
          dispbuf[keycount+2]=19;
          }
          keycount++;
          if(keycount==6)
          {
          keycount=6;
          }
          else if(keycount>6)
          {
          keycount=6;
          keyoverflag=1;//key overflow
          }
          }
          else if(key==12)//delete key
          {
          if(keycount>0)
          {
          keycount--;
          getps[keycount]=0;
          dispbuf[keycount+2]=16;
          }
          else
          {
          keyoverflag=1;
          }
          }
          else if(key==15)//enter key
          {
          if(keycount!=pslen)
          {
          errorflag=1;
          rightflag=0;
          second3=0;
          }
          else
          {
          for(i=0;ikeycount;i++)
          {
          if(getps[i]!=ps[i])
          {
          i=keycount;
          errorflag=1;
          rightflag=0;
          second3=0;
          goto a2;
          }
          }
          errorflag=0;
          rightflag=1;
          a2: i=keycount;
          }
          }
          temp=temp 0x0f;
          while(temp!=0x0f)
          {
          temp=p3;
          temp=temp 0x0f;
          }
          keyoverflag=0;//?????????
          }
          }
          }
          }
          void t0(void) interrupt 1 using 0
          {
          th0=(65536-500)/256;
          tl0=(65536-500)%256;
           
          flashcount++;
          if(flashcount==8)
          {
          flashcount=0;
          p0=dispcode[dispbuf[dispcount]];
          p2=dispbit[dispcount];
          dispcount++;
          if(dispcount==8)
          {
          dispcount=0;
          }
          }
           
          if((errorflag==1) (rightflag==0))
          {
          bb++;
          if(bb==800)
          {
          bb=0;
          alarmflag=~alarmflag;
          }
          if(alarmflag==1)//sound alarm signal
          {
          p1_7=~p1_7;
          }
           
          aa++;
          if(aa==800)//light alarm signal
          {
          aa=0;
          p1_0=~p1_0;
          }
          second3++;
          if(second3==6400)
          {
          second3=0;
          errorflag=0;
          rightflag=0;
          alarmflag=0;
          bb=0;
          aa=0;
          }
          }
          else if((errorflag==0) (rightflag==1))
          {
          p1_0=0;
          cc++;
          if(cc1000)
          {
          okflag=1;
          }
          else if(cc2000)
          {
          okflag=0;
          }
          else
          {
          errorflag=0;
          rightflag=0;
          p1_7=1;
          cc=0;
          oka=0;
          okb=0;
          okflag=0;
          p1_0=1;
          }
          if(okflag==1)
          {
          oka++;
          if(oka==2)
          {
          oka=0;
          p1_7=~p1_7;
          }
          }
          else
          {
          okb++;
          if(okb==3)
          {
          okb=0;
          p1_7=~p1_7;
          }
          }
          }
           
          if(keyoverflag==1)
          {
          p1_7=~p1_7;
          }
          }



          評論


          相關(guān)推薦

          技術(shù)專區(qū)

          關(guān)閉
          看屁屁www成人影院,亚洲人妻成人图片,亚洲精品成人午夜在线,日韩在线 欧美成人 (function(){ var bp = document.createElement('script'); var curProtocol = window.location.protocol.split(':')[0]; if (curProtocol === 'https') { bp.src = 'https://zz.bdstatic.com/linksubmit/push.js'; } else { bp.src = 'http://push.zhanzhang.baidu.com/push.js'; } var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(bp, s); })();