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

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

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

門禁的配件差不多買回來了。at89s52要二十塊,24c02要十塊,7805要5塊,洞洞板一小塊要十塊,id讀卡器45塊。唉,什么都貴死了。
     光這個(gè)的價(jià)格就可以買個(gè)好的單門門禁了。但是制作的樂趣卻是買不到的,
上次的IIC和韋根26的程序從這里打開:http://www.torrancerestoration.com/mcu/1231.html

累!腦力勞動(dòng)比體力勞動(dòng)要累多了!寫得并調(diào)式好幾個(gè)程序花了我不少精力,打字都嫌累了,貼上幾個(gè)程序:

/*////////////////////////////////////
函數(shù)原型:
函數(shù)說明:串口接收中斷
版本:V1.0.0
程序員:LIY12586
////////////////////////////////////*/
void ser() interrupt 4
{
   RI=0;
   z=SBUF;
   ai=1;
   
}
/*////////////////////////////////////
函數(shù)原型:void sound(uchar a)
函數(shù)說明:蜂鳴器發(fā)聲,a為需要發(fā)出多少次DIDI音
版本:V1.0.0
程序員:LIY12586
////////////////////////////////////*/
void sound(uchar a)
{
    uchar x,y;
   for(;a>0;a--)
   {
      for(x=255;x>0;x--)
      {
         beep=0;
         for(y=150;y>0;y--)
         beep=1;
         beep=0;
       }
       ysms(500);
    }   
}
void ysms(unsigned int x)
{
   unsigned int a;
   unsigned int b;
   for(a=x;a>0;a--)
   {
       for(b=50;b>0;b--);
   }
}
/*////////////////////////////////////
函數(shù)原型:void inscard(void)
函數(shù)說明:存入卡號(hào)到EEPROM
版本:V1.0.0
程序員:LIY12586
////////////////////////////////////*/
void inscard(void)
{
    while(1)
   {
       if(re())
      {
          if(iscard()==0)//如果沒有這卡號(hào)/
         {
            uchar a,b;
         
            b=ckdz();     //查找空置/
            for(a=3;a<6;a++)
            {
               wt24c(b,WG[a]);
               ys100us(1000);
               b++;
                        
            }
         //   wt24c(0,b);
            ys100us(1000);
            sound(1);
            break;
         }
         sound(2);
         break;
      }
      if(key()==12)
      {
         sound(1);
         break;
      }
   
   }
}

/*////////////////////////////////////
函數(shù)原型:void delcard(void)
函數(shù)說明:從EEPROM中刪除卡號(hào)
版本:V1.0.0
程序員:LIY12586
////////////////////////////////////*/
void delcard(void)
{
    while(1)
   {
       if(re())
      {
          if(iscard()!=0)   //如果有這張卡號(hào)/
         {
            uchar a,b;
         
            b=iscard();     //查找空置/
            for(a=0;a<3;a++)
            {
               wt24c(b,0xff);
               ys100us(1000);
               b=b+1;
                  
            }
         //   wt24c(0,b);
            ys100us(1000);      
            sound(1);
            break;
         }
         sound(2);
         break;
      }
      if(key()==12)
      {
         sound(2);
         break;
      }
   }
}
/*////////////////////////////////////
函數(shù)原型:uchar iscard(void)
函數(shù)說明:查找是否有此卡
版本:V1.0.0
程序員:LIY12586
////////////////////////////////////*/
uchar iscard(void)
{
    
       uchar a,b;
      for(a=8;a<128;a++)
      {
         if(rd24c(a)==WG[3])
         {
            a++;
            if(rd24c(a)==WG[4])
            {
               a++;
               if(rd24c(a)==WG[5])
               {
                  b=a-2;
                  return b;
               } 
            }      
         }
         if(a==127)return 0;
       }
   
}
/*////////////////////////////////////
函數(shù)原型:uchar ckdz(void)
函數(shù)說明:查找EEPROM的空白位置地址
版本:V1.0.0
程序員:LIY12586
////////////////////////////////////*/
uchar ckdz(void)//查空地址/
{
    uchar a,b,c;
   for(a=2;a<126;a++)
   {
      c=a;
      c++;
      if(rd24c(a)==0xff)
      {
         a++;
         if(rd24c(a)==0xff)
         {
            a++;
            if(rd24c(a)==0xff)
            {
               b=a-2;
               return b;
            } 
         }      
      }
      if(c==126)return 0xff;
    }
} 

/*////////////////////////////////////
函數(shù)原型:void readcard(void)
函數(shù)說明:讀卡正確
版本:V1.0.0
程序員:LIY12586
////////////////////////////////////*/
void readcard(void)
{
   if(re())
   {
      
        if(iscard()!=0)
      {
         SEND(&WG[0]);
         open();

      }sound(2);
    }
}
/*////////////////////////////////////
函數(shù)原型:void open(void)
函數(shù)說明:打開
版本:V1.0.0
程序員:LIY12586
////////////////////////////////////*/
void open(void)
{
   
       //out=0;
      SEND(&WG[0]);
      sound(1);
      ysms(10000);
      //out=1;
      
   
}
關(guān)閉窗口

相關(guān)文章