专注电子技术学习与研究
当前位置:单片机教程网 >> MCU设计实例 >> 浏览文章

自己做的门禁系统2

作者:佚名   来源:本站原创   点击数:  更新时间:2011年06月12日   【字体:

门禁的配件差不多买回来了。at89s52要二十块,24c02要十块,7805要5块,洞洞板一小块要十块,id读卡器45块。唉,什么都贵死了。
     光这个的价格就可以买个好的单门门禁了。但是制作的乐趣却是买不到的,
上次的IIC和韦根26的程序从这里打开:http://www.51hei.com/mcu/1231.html

累啊!脑力劳动比体力劳动要累多了!写得并调式好几个程序花了我不少精力,打字都嫌累了,贴上几个程序:

/*////////////////////////////////////
函数原型:
函数说明:串口接收中断
版本:V1.0.0
程序员:LIY12586
////////////////////////////////////*/
void ser() interrupt 4
{
   RI=0;
   z=SBUF;
   ai=1;
   
}
/*////////////////////////////////////
函数原型:void sound(uchar a)
函数说明:蜂鸣器发声,a为需要发出多少次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--);
   }
}
/*////////////////////////////////////
函数原型:void inscard(void)
函数说明:存入卡号到EEPROM
版本:V1.0.0
程序员:LIY12586
////////////////////////////////////*/
void inscard(void)
{
    while(1)
   {
       if(re())
      {
          if(iscard()==0)//如果没有这卡号/
         {
            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;
      }
   
   }
}

/*////////////////////////////////////
函数原型:void delcard(void)
函数说明:从EEPROM中删除卡号
版本:V1.0.0
程序员:LIY12586
////////////////////////////////////*/
void delcard(void)
{
    while(1)
   {
       if(re())
      {
          if(iscard()!=0)   //如果有这张卡号/
         {
            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;
      }
   }
}
/*////////////////////////////////////
函数原型:uchar iscard(void)
函数说明:查找是否有此卡
版本: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;
       }
   
}
/*////////////////////////////////////
函数原型:uchar ckdz(void)
函数说明:查找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;
    }
} 

/*////////////////////////////////////
函数原型:void readcard(void)
函数说明:读卡正确
版本:V1.0.0
程序员:LIY12586
////////////////////////////////////*/
void readcard(void)
{
   if(re())
   {
      
        if(iscard()!=0)
      {
         SEND(&WG[0]);
         open();

      }sound(2);
    }
}
/*////////////////////////////////////
函数原型:void open(void)
函数说明:打开
版本:V1.0.0
程序员:LIY12586
////////////////////////////////////*/
void open(void)
{
   
       //out=0;
      SEND(&WG[0]);
      sound(1);
      ysms(10000);
      //out=1;
      
   
}
关闭窗口

相关文章