辜渝傧

13037102709

027-87870986

教学实训

您当前的位置:首页 > 教学资源 > 实训方案 >

RFID实训|第二部分 综合实验——智能门禁系统

发布者:唯众    布时间:2020-12-03 11:50:13    点击量:

1. 智能门禁系统
1.1 项目介绍
       随着高科技的蓬勃发展,智能化管理已经走进了人们的社会生活,一座座智能化大厦拔地而起,适应信息的时代需要,作为跨世纪使用的建筑和办公环境,必须在功能上满足当前和未来发展的需求,成为文化和经济发展的基地。 
感应式IC卡出入管理控制系统(简称门禁系统),具有对门户出入控制、实时监控、保安防盗报警等多种功能,它主要方便内部员工出入,杜绝外来人员随意进出,既方便了内部管理,又增强了内部的保安,从而为用户提供一个高效和具经济效益的工作环境。 
        它在功能上实现了通讯自动化(CA)、办公自动化 (OA) 和管理自动化 (BA), 以综合布线系统为基础,以计算机网络为桥梁,全面实现对通讯系统、办公自动化系统的综合管理。 
        门禁系统作为一项先进的高科技技术防范和管理手段,在一些经济发达的国家和地区已经广泛应用于科研、工业、博物馆、酒店、商场、医疗监护、银行、监狱等,特别是由于系统本身具有隐蔽性,及时性等特点,在许多领域的应用越来越广泛。
        使用者在门外出示经过授权的感应卡,经读卡器识别确认合法身份后,控制器驱动打开电锁放行,并记录进门时间。按开门按钮,打开电锁,直接外出。  适用于安全级别一般的环境,可以有效地防止外来人员的非法进入。是最常用的管理模式。
1.2 项目搭建
        本方案实现智能门禁和智能安防。由唯众125K读卡器、125K电子标签、M4网关、433M无线通讯模块、节点板。
程序流程:
智能门禁系统

  1. M4网关插上唯众433M无线模块,唯众125K读卡器通过433M无线连接M4模块
  2. M4进入卡注册界面,对125K电子标签进行注册
  3. 读卡器读到卡,上传信息卡ID给M4,M4判断是否注册,注册则通知继电器节点打开电磁锁,未注册则通知 “未注册”
  4. M4进入刷卡界面,显示信息卡信息,并执行开门功能
  5. 还可加入更多唯众传感器节点,例如人体红外、烟雾报警、雨滴等,M4一旦检测到传感器超过阀值,则通过WiFi或者4G将警报信息上传至云服务器,实现智能安防功能
1.3 项目实现
#include "menjin.h"
 
#define menjin125ADDR        1024*924*12 //从最后100K字节开始写起
 
u8*const duka125[4]={"智能门禁安防系统","注册","返回","清除"};
u8 jidianqi[40]={'#',0,0,0,0,0,0,0,0,0,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,'$'};
u8 CardNum_125[50];
 
void menjin()
{
         u8 key1,key2; 
         u8 *caption;                       //标题
         u8 res,i;
         u8 Str[20];
         _btn_obj* zbtn=0;            //注册按钮控件
         _btn_obj* rbtn=0;            //返回按钮控件
        
         usart3_init(9600);
         caption=(u8*)duka125[0];//无线传输   
         gui_fill_rectangle(0,gui_phy.tbheight,lcddev.width,lcddev.height-gui_phy.tbheight,LGRAY);         //填充背景色
        app_filebrower(caption,0X07);                                                              //显示标题
        
        
         zbtn=btn_creat(5,lcddev.height-gui_phy.tbheight,2*gui_phy.tbheight+8,gui_phy.tbheight-1,0,0x03);//创建文字按钮
         if(zbtn==NULL)res=1;       //没有足够内存够分配
         else
         {                                                                                                                                                            
                   zbtn->caption=(u8*)duka125[1];//重画
                   zbtn->font=gui_phy.tbfsize;//设置新的字体大小          
                   zbtn->bcfdcolor=RED;      //按下时的颜色
                   zbtn->bcfucolor=WHITE; //松开时的颜色
                   btn_draw(zbtn);//画按钮
        }
         rbtn=btn_creat(400,lcddev.height-gui_phy.tbheight,2*gui_phy.tbheight+8,gui_phy.tbheight-1,0,0x03);//创建文字按钮
         if(rbtn==NULL)res=1;       //没有足够内存够分配
         else
         {                                                                                                                                                            
                   rbtn->caption=(u8*)duka125[2];//重画
                   rbtn->font=gui_phy.tbfsize;//设置新的字体大小          
                   rbtn->bcfdcolor=RED;      //按下时的颜色
                   rbtn->bcfucolor=WHITE; //松开时的颜色
                   btn_draw(rbtn);//画按钮
        }
         gui_show_string("卡号:",35,138,107,470,24,BLACK);
         while(1)
         {
                   tp_dev.scan(0);                 
                   in_obj.get_key(&tp_dev,IN_TYPE_TOUCH);    //得到按键键值
                   key1=btn_check(zbtn,&in_obj);                //扫描注册按键
                   key2=btn_check(rbtn,&in_obj);                 //扫描注册按键
                 if(system_task_return)    //TPAD返回
                   {    
                            break;//接收模式,直接退出                             
                 }           
                   if(key1)
                   {
                            if(((zbtn->sta&0X80)==0))//按钮状态改变了
                            {
                                     zhuce();
                                     app_filebrower(caption,0X07);                                                              //显示标题
                                     gui_show_string("卡号:",35,138,107,470,24,BLACK);
                                     btn_draw(rbtn);//画按钮
                                     btn_draw(zbtn);//画按钮
                                     W25QXX_Read(CardNum_125,menjin125ADDR,50);
                            }
                   }
        
                   if(key2)
                   {
                            if(((rbtn->sta&0X80)==0))//按钮状态改变了
                            {
                                     break;
                            }
                   }
                   if(USART3_RX_STA&(1<<15))
                   {
                            if(USART3_RX_BUF[0]=='#'&&USART3_RX_BUF[39]=='$')
                            {
                                     if(USART3_RX_BUF[11]==0x0c)
                                     {
                                               sprintf((char*)Str,"%2x %2x %2x %2x ",USART3_RX_BUF[16],USART3_RX_BUF[17],USART3_RX_BUF[18],USART3_RX_BUF[19]);
                                               gui_show_ptstr(120,138,450,170,0,RED,24,Str,0);
                                               for(i=0;i<10;i++)
                                               {
                                                        if(CardNum_125[i*5]==1)
                                                        {
                                                                 if(CardNum_125[i*5+1]==USART3_RX_BUF[16])
                                                                 {
                                                                           if(CardNum_125[i*5+2]==USART3_RX_BUF[17])
                                                                           {
                                                                                    if(CardNum_125[i*5+3]==USART3_RX_BUF[18])
                                                                                    {
                                                                                             if(CardNum_125[i*5+4]==USART3_RX_BUF[19])
                                                                                             {
                                                                                                       break;
                                                                                             }
                                                                                    }
                                                                           }
                                                                 }
                                                        }
                                               }
                                               if(i<10)
                                               {
                                                        window_msg_box((lcddev.width-200)/2,(lcddev.height-70)/2-15,300,100,"刷卡成功!",(u8*)APP_REMIND_CAPTION_TBL[gui_phy.language],24,0,0,0);
                                                        u3_printf("%s",jidianqi); 
                                                        delay_ms(500);
                                                        gui_fill_rectangle(140,350,300,100,LGRAY);
                                              
                                               }
                                               else
                                               {
                                                        window_msg_box((lcddev.width-200)/2,(lcddev.height-70)/2-15,300,100,"此卡未注册!",(u8*)APP_REMIND_CAPTION_TBL[gui_phy.language],24,0,0,0);
                                                        delay_ms(500);
                                                        gui_fill_rectangle(140,350,300,100,LGRAY);
                                               }
                                    
                                     }
                                     else
                                     {
                                               gui_fill_rectangle(120,138,330,32,LGRAY);
                                     }
                            }
                            USART3_RX_STA=0;
                  
                   }
         }
         btn_delete(rbtn);     //删除按钮
         btn_delete(zbtn);    //删除按钮
        
 
}
 
void zhuce()
{
         u8 key1,key2;
         _btn_obj* rbtn=0;            //返回按钮控件
         _btn_obj* cbtn=0;            //清除按钮控件
         u8 *caption;                       //标题     
         u8 res,i;
         u8 Str[20];
         caption=(u8*)duka125[1];//无线传输   
         gui_fill_rectangle(0,gui_phy.tbheight,lcddev.width,lcddev.height-gui_phy.tbheight,LGRAY);         //填充背景色
        app_filebrower(caption,0X07);                                                              //显示标题
         W25QXX_Read(CardNum_125,menjin125ADDR,50);
         rbtn=btn_creat(400,lcddev.height-gui_phy.tbheight,2*gui_phy.tbheight+8,gui_phy.tbheight-1,0,0x03);//创建文字按钮
         if(rbtn==NULL)res=1;       //没有足够内存够分配
         else
         {                                                                                                                                                            
                   rbtn->caption=(u8*)duka125[2];//重画
                   rbtn->font=gui_phy.tbfsize;//设置新的字体大小          
                   rbtn->bcfdcolor=RED;      //按下时的颜色
                   rbtn->bcfucolor=WHITE; //松开时的颜色
                   btn_draw(rbtn);//画按钮
        }
        
         cbtn=btn_creat(5,lcddev.height-gui_phy.tbheight,2*gui_phy.tbheight+8,gui_phy.tbheight-1,0,0x03);//创建文字按钮
         if(cbtn==NULL)res=1;       //没有足够内存够分配
         else
         {                                                                                                                                                             
                   cbtn->caption=(u8*)duka125[3];//重画
                   cbtn->font=gui_phy.tbfsize;//设置新的字体大小          
                   cbtn->bcfdcolor=RED;      //按下时的颜色
                   cbtn->bcfucolor=WHITE; //松开时的颜色
                   btn_draw(cbtn);//画按钮
        }
         gui_show_string("卡号:",35,138,107,470,24,BLACK);
         while(1)
         {
                   tp_dev.scan(0);                 
                   in_obj.get_key(&tp_dev,IN_TYPE_TOUCH);    //得到按键键值
                   key1=btn_check(rbtn,&in_obj);                 //扫描注册按键
                   key2=btn_check(cbtn,&in_obj);                //扫描注册按键
                   if(system_task_return)    //TPAD返回
                   {    
                            break;//接收模式,直接退出                             
                 }           
                   if(key1)
                   {
                            if(((rbtn->sta&0X80)==0))//按钮状态改变了
                            {
                                     break;
                            }
                   }
                   if(key2)
                   {
                            if(((cbtn->sta&0X80)==0))//按钮状态改变了
                            {
                                     for(i=0;i<50;i++)
                                     {
                                               CardNum_125[i]=0;
                                     }
                                     W25QXX_Write(CardNum_125,menjin125ADDR,50);
                            }
                   }
                   if(USART3_RX_STA&(1<<15))
                   {
                            if(USART3_RX_BUF[0]=='#'&&USART3_RX_BUF[39]=='$')
                            {
                                     if(USART3_RX_BUF[11]==0x0c)
                                     {
                                               sprintf((char*)Str,"%2x %2x %2x %2x ",USART3_RX_BUF[16],USART3_RX_BUF[17],USART3_RX_BUF[18],USART3_RX_BUF[19]);
                                               gui_show_ptstr(120,138,450,170,0,RED,24,Str,0);
                                               for(i=0;i<10;i++)
                                               {
                                                        if(CardNum_125[i*5]==1)
                                                        {
                                                                 if(CardNum_125[i*5+1]==USART3_RX_BUF[16])
                                                                 {
                                                                           if(CardNum_125[i*5+2]==USART3_RX_BUF[17])
                                                                           {
                                                                                    if(CardNum_125[i*5+3]==USART3_RX_BUF[18])
                                                                                    {
                                                                                             if(CardNum_125[i*5+4]==USART3_RX_BUF[19])
                                                                                             {
                                                                                                       break;
                                                                                             }
                                                                                    }
                                                                           }
                                                                 }
                                                        }
                                               }
                                               if(i<10)
                                               {
                                                        window_msg_box((lcddev.width-200)/2,(lcddev.height-70)/2-15,300,100,"此卡已注册!",(u8*)APP_REMIND_CAPTION_TBL[gui_phy.language],24,0,0,0);
                                                        delay_ms(500);
                                                        gui_fill_rectangle(140,350,300,100,LGRAY);
                                              
                                               }
                                               else
                                               {
                                                        for(i=0;i<10;i++)
                                                        {
                                                                 if(CardNum_125[i*5]==0)
                                                                           break;
                                                        }
                                                        CardNum_125[i*5]=1;
                                                        CardNum_125[i*5+1]=USART3_RX_BUF[16];
                                                        CardNum_125[i*5+2]=USART3_RX_BUF[17];
                                                        CardNum_125[i*5+3]=USART3_RX_BUF[18];
                                                        CardNum_125[i*5+4]=USART3_RX_BUF[19];
                                                        W25QXX_Write(CardNum_125,menjin125ADDR,50);
                                                        window_msg_box((lcddev.width-200)/2,(lcddev.height-70)/2-15,300,100,"注册成功!",(u8*)APP_REMIND_CAPTION_TBL[gui_phy.language],24,0,0,0);
                                                        delay_ms(500);
                                                        gui_fill_rectangle(140,350,300,100,LGRAY);
                                                        W25QXX_Read(CardNum_125,menjin125ADDR,50);
                                               }
                                    
                                     }
                                     else
                                     {
                                               gui_fill_rectangle(120,138,330,32,LGRAY);
                                     }
                            }
                   USART3_RX_STA=0;
                   }
                  
                  
         }
         btn_delete(rbtn);     //删除按钮
         btn_delete(cbtn);    //删除按钮


上一篇:RFID实训|13.56M读卡电路搭建和程序实训

下一篇:RFID实训|公交刷卡系统