專注電子技術(shù)學(xué)習(xí)與研究
當(dāng)前位置:單片機教程網(wǎng) >> MCU設(shè)計實例 >> 瀏覽文章

自己做的門禁系統(tǒng)3

作者:佚名   來源:本站原創(chuàng)   點擊數(shù):  更新時間:2011年06月13日   【字體:

   之前上傳的所有門禁制作程序絕大部分為本人原創(chuàng)(只有I2C程序為網(wǎng)上收集本人更改),所有看到的人可以用來用作個人討論,學(xué)習(xí)和研究。禁止完全使用或修改使用在以盈利為目的的商業(yè)用途。如有違反,本人保留一切權(quán)利。解釋權(quán)歸本人所有。 

  昨天晚上終于完成了按鍵操作,由于太晚沒上傳,大部分功能已經(jīng)完成,一個簡單(功能相對于專業(yè)門禁來說簡單,制作對我來說相當(dāng)復(fù)雜,但也是體現(xiàn)我的單片機和電子技術(shù)水平又有提高)的門禁可以使用了,目前的功能有:讀卡開門,密碼開門,加卡,刪卡,更改密碼,系統(tǒng)初始化。后期要加上:遠(yuǎn)程控制開門,加卡,刪卡,監(jiān)控等。下面是程序:
 

/*////////////////////////////////////
函數(shù)原型:void psw(void)
函數(shù)說明:密碼寫入EEPROM中
版本:V1.0.0
程序員:LIY12586
////////////////////////////////////*/
void psw(void)
{
   uchar a=0,b=2,c,d,x=0;
   timer=0;
   while(1)
   {      
         
         c=key();
         if(c==12)
            {            
               sound(1);
               break;
            }
         if(ex==1)
         {
            
            sound(1);
            ex=0;
             break;
         }   
            if(c!=0)
            {
               if(a<6)
               {
                  keybuff[a]=c;
                  a++;
                  if(a==6)sound(2);
               }
               else if(a>6,a<13)
               {
                  if(c!=keybuff[x])
                  {
                  
                     sound(20);
                     x=0;
                     a=0;
                     break;
                  }
                     a++;
                     x++;
               
                  if(a==12)
                  {
                     a=0;
                     x=0;
                     b=2;
                     for(d=0;d<6;d++)
                     {
                        wt24c(b,keybuff[d]);
                        ys100us(1000);
                        b++;
                     }
                     SEND(&keybuff[0]);
                     break;
                  }
               
                }
               
             }
      
         
       
      
   }
}
/*////////////////////////////////////
函數(shù)原型:bit keyscan(void)
函數(shù)說明:鍵盤操作掃描
版本:V1.0.0
程序員:LIY12586
////////////////////////////////////*/
bit keyscan(void)
{
   uchar a=1,c,d;
   scan=key();
   if(scan!=0)
   {
      
      if(scan!=11)
      {
         d=scan;
         timer=0;
         keybuff[0]=scan;
         scan=0;
         
         while(1)
         {
            if(d==12)
            {            
               sound(1);
               break;
            }
            
            c=key();
            if(c==12)
            {            
               sound(1);
               break;
            }
            else if(ex==1)
            {
               
               sound(1);
               ex=0;
                break;
            }   
            else if(c!=0)
            {
               keybuff[a]=c;
               a++;
               if(a==6)
               {
                  a=0;
                  SEND(&keybuff[0]);
                  return 1;
                  break;
               }
            }
   
         }
      }
      
   }
   
   return 0;
}
/*////////////////////////////////////
函數(shù)原型:void password(void)
函數(shù)說明:確認(rèn)密碼
版本:V1.0.0
程序員:LIY12586
////////////////////////////////////*/
bit password(void)
{
   uchar a,b;
   if(keyscan())
   {
         b=2;
         for(a=0;a<6;a++)
         {
            if(keybuff[a]!=rd24c(b))
            {
            break;
            }
            b++;
            if(b==8)return 1;
         }
         if(b!=8)
         {   

            sound(5);
//            LED=0;
            return 0;
         }
      
         
   }
}

/*////////////////////////////////////
函數(shù)原型:void systeminit(void)
函數(shù)說明:系統(tǒng)初始化
版本:V1.0.0
程序員:LIY12586
////////////////////////////////////*/
void systeminit(void)
{
    uchar a;
      wt24c(0,0x02);
      ys100us(1000);
      wt24c(1,0xab);
      ys100us(1000);
      wt24c(2,0x01);
      ys100us(1000);
      wt24c(3,0x02);
      ys100us(1000);
      wt24c(4,0x03);
      ys100us(1000);
      wt24c(5,0x04);
      ys100us(1000);
      wt24c(6,0x05);
      ys100us(1000);
      wt24c(7,0x06);
      ys100us(1000);
      
   for(a=8;a<128;a++)
   {
      if(rd24c(a)!=0xff)
      {
         //ysms(100)
         wt24c(a,0xff);
         ys100us(1000);
      }
      
   }
   sound(5);
}
關(guān)閉窗口

相關(guān)文章