原创 智能门禁系统

2008-6-27 12:27 3932 3 3 分类: 工程师职场

智能门禁系统<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />


郭德胜 李建军  王伟波


指导教师:齐明


 


  要:智能门禁系统采用凌阳十六位单片机作为系统控制核心,利用其强大的语音识别功能,不仅实现了语音播放功能,完成了语音提示的要求,而且实现了语音控制门禁系统;利用其内置的Flash闪存,实现了密码的断电保护。除此而外,在键盘输入方面,强大的功能选择键满足了系统的要求;16*2液晶显示器的选择使操作要求清晰明了。此套智能门禁系统强烈体现了其人性化的一面。


关键词:智能门禁系统、语音识别、凌阳十六位单片机。


引言


家用防盗门早已经进入到千家万户,但防盗门的操作麻烦给用户带来了许多不便,当今市场迫切需要一种既安全又方便的门禁系统,鉴于此,我们的“智能门禁系统”——带语音识别、液晶显示功能的电子密码锁便应运而生。


为了向大家介绍此智能门禁系统,我们将从以下几个方面介绍:


1、系统的制作意义。


2、系统的制作早期构想及其实现方案简介。


3、系统功能最终实现及演示。


4、系统硬件部分原理介绍。


5、系统软件部分设计实现。


6、对系统的自我评价。(存在及要解决的问题


7、制作心得和体会。


8、参考文献。


9、附录(一):凌阳单片机最小系统。


10、  附录(二):凌阳单片机下电子密码锁程序实现。


11、  附录(三):器件列表。


1.系统的制作意义


现在人们生活水平提高了,安全防范,是人们考虑的首要问题。而锁是解决安全问题的重要产品。目前市场上的电子锁产品功能不全,性能和安全性不高,且造价高。低质量的电子锁,给用户的财产安全造成很大威胁,同时,由于功能的不健全,给用户的使用带来了一定麻烦。故我们试图研制一种智能化、多功能、更人性化的门禁系统。


我们研制的带语音识别功能电子控制密码锁,不仅给用户带来了安全的保障,方便的享受,而且此电子锁的语音识别功能更加体现了他人性化的一面,此种类型的电子密码锁将成为未来社会的供求亮点。


2.系统的制作早期构想及其实现方案简介


1.早期构想


预期实现功能如下:


1)、键盘简化及编码方式的改进;


键盘简化及编码方式的改进:普通数字键密码锁虽然有使用简单的特点,但是键盘暴露在外,易受破坏,或者保密性不高;此外,键盘数量的简化又同时增加了使用的难度,用户使用不方便。大家可能见到过一些进口的温控制器(如日本RKCINSTRUMENT INC.生产的REX_C700温控器)的面板设计为:温度测量只用4LED数码管显示,输入设定值显示也用4LED。综合以上因素考虑,我们采取四按键的形式,输入键分为加、减、左、右移动键,按下加法键(减法键)确定一位密码的值,然后使用左右移动键移向下一位密码,再一次使用加、减键确定此位密码的值。(备注:这部分虽然没有实现,但我们的16位键盘设置更加体现了系统功能的强大性)


2)、语音识别系统控制;语音识别功能,语音控制门禁开关。


3)、语音提示功能;


4)、自动实现报警;当门禁系统输入密码错误过多时,自动报警


5)、断电密码保护;出现断电、多次错误密码输入时的处理


6)、限时开门系统;(这部分功能我们没能实现,很是遗憾)


7)、液晶显示功能;


在初期设计电路时,我们计划采取51单片机作为我们的控制核心,然而,语音识别功能、语音提示功能、密码断电保护功能需要我们外扩集成芯片才能满足系统要求。其功能实现原理方框图如下:


<?xml:namespace prefix = v ns = "urn:schemas-microsoft-com:vml" />


在此种条件下我们用51单片机做出了一个简单的系统,基本实现了电子密码锁的键盘输入和液晶显示功能。具体电路图如下:



 


 


其软件编程实现程序见附录(一):


其实现功能如下:


1、设置密码,断电不保护;


2、输入密码,与系统原有密码或者设置新密码比较;


3、液晶显示功能;


4、报警功能;


显然,这个“最小系统”的制作无法满足我们预期的功能实现,如果采用外扩集成芯片的做法,不仅从技术上,还是从经济方面考虑都不是一个明智的选择。鉴于此,我们采用凌阳单片机作为我们的控制电路核心,凌阳十六位单片机不仅内置32kFlash(闪存),而且集成了语音识别模块,从根本上,凌阳单片机满足了系统的基本要求,具体功能实现以及电路设计在以下详细介绍。


3.系统功能最终实现及演示


此系统现阶段包括以下几个模块:


1)、键盘输入密码


此系统采用4*4按键输入模式,密码初始设置为4位,(从软件上很容易实现更多位数的密码操作,为操作演示计,我们采用4位)。


各个按键功能的定义如下:


1、0~9数字健指定为密码设置健(仅且只有他们能够作为密码值)


2、A——确认健(按下此键,即比较输入密码值正确如否)


3、B——取消键(按下此键,即取消上一次操作)


4、C——开启语音功能键(按下此键,再次输入密码,就可以开启语音控制功能)


5、D——关闭语音功能键(按下次键,就可以关闭语音控制功能)


6、E——修改密码键(按下次键,再次输入密码,通过验证后,连续输入两次新的密码就可以设置新的密码)


7、F——更改语音控制口令(按下次键,再次输入密码,通过验证后,即可进入语音口令修改程序操作)


2)、语音控制输入


进入语音控制功能后,先进行语音控制训练操作(训练过后此操作可跳过),训练成功后,方可进行语音控制,并且时时可以关闭语音功能。


此外,语音口令还可以时时修改,再次进行语音控制训练操作即可。


3)、密码修改操作


此系统的密码设置存在Flash中,断电不丢失,密码修改后,系统原密码作废,新的密码生效,并存入Flash中。


4)、语音提示操作


对应于每一种操作,系统均给予一定的语音提示。如:“请输入密码”、“密码错误”等。


5)、液晶显示功能


对应于每一种操作,系统均给予一定的显示提示,方便操作。


6)、液晶背光功能实现


为了实现液晶背光功能,我们设计了一下三种电路:超声波探测电路、光敏传感电路、按键触发电路,在光线好的情况下,液晶不背光显示,光线差时,有按键或探测到有人接近时背光显示。


7)、系统执行机构


系统执行机构我单片机I/O口输出控制的继电器。


8)、报警蜂鸣器


9)、电源信号指示灯


10)、控制信号指示灯


4.系统硬件部分原理介绍


此系统硬件部分电路核心部分为凌阳单片机及其外围电路(包括语音识别、输出电路),外围电路有:键盘输入、液晶显示、执行机构电路,此外,为了实现液晶显示器的背光功能,我们采用了超声波探测电路、光敏传感电路、输出延时电路等。电路总体设计模块方框图如下:





凌阳十六位单片机控制系统




液晶显示


提示功能的实现




语音输出




 


键盘输入电路




 


15V5V电源部分




语音输入电路




执行、


报警机构




超声波探测电路、光敏传感电路、输出延时电路、键盘按键检测。

<?xml:namespace prefix = w ns = "urn:schemas-microsoft-com:office:word" />


控制液晶显示背光功能

 


 


 


 


 


 


 


 


 


 



为了详细介绍我们的电路功能模块,我们将在下面分块介绍本系统的各个功能模块:


1、电源部分:


 


 


 


 


 


 


 


 


 


 


 


 


2、电源信号灯:


3、凌阳十六位单片机控制电路:见附录(一)


4、被控制的继电器:


5、控制信号灯:


6、蜂鸣器:


7、键盘输入部分:


8、液晶显示部分:


9、背光功能控制模块


基本方框图如下:



1)、超声波探测发射部分:(含波形)


 


 


 


 


 


 


 


2)、超声波探测接收放大电路:



3)、光敏传感检测电路:


 


 


 


 


 


 


 


 


4)、输入信号延迟电路:



5.系统软件部分设计实现


1、软件设计操作平台简介:(μ'nSP? IDE



μ'nSP? IDE工作界面如下:



2、此系统功能复杂,但软件设计较为简单,程序功能实现简介图如下:





开始




系统初始化




键盘扫描




数字键




输入四位数字则为密码,否则跳到功能键上




检验密码正确与否




设置新的密码




开启语音功能




关闭语音功能




更改语音口令




取消




A




F




E




D




C




B




按照液晶显示提示进行操作,输入四位密码后按确认键。




返回




密码正确执行相应操作;密码错误超过三次报警

 


 


 


 


 


 


 


 


 


 


 


 


 


 


 


 


 


 


 


 


 


 


 


 


 


 


 


 


 


 


 


 


 


 


 


 


 


 


 


 


 



对操作程序的解释以及要求:


1、直接输入密码开门;


输入四位密码后按确认键,比较密码,密码正确表开启门禁系统,并有“门已经打开,请进”的提示余音。


2、设置新的密码;


按下B键后,输入原密码,确认后输入新的密码,确认后再次输入新的密码,检验正确后,密码修改成功,原密码作废。


3、开启语音功能;


按下C键,输入密码确认后,进入语音识别模式。如果是第一次进入语音识别模式,需要进行语音识别训练,训练两遍正确后,完成训练操作,此时语音识别功能实时监测。在语音识别实时监测的同时,我们的键盘扫描并没有停止,也就是说我们的键盘输入等级高于语音识别模式,在任何情况下键盘输入都是有效的。


4、关闭语音识别功能;


按下D键,不需要输入密码即可关闭语音识别功能,要想开启此项功能,必须按下C键开启语音识别功能。


5、更改语音口令;


按下E键,进入语音识别口令修改模块,输入密码确认后,进入语音口令修改训练模块,根据语音提示以及液晶显示很方便的就可以成功更改语音口令。


6、取消键;


按下F键,即可取消所有操作,回到系统初始化后的界面。


主程序见附录(二):


6.对系统的自我评价


            在总体上,我们对这个系统的设计还是比较满意的,但是,虽然我们对这个项目投入了大量的时间和精力,由于知识有限,我们在很多方面有很多的不足之处。


        以下我将从硬件和软件两个方面来阐述这个系统的各个部分:


硬件部分:


1.我们认为,我们做得比较成功的地方就是通过超声波探测、光敏传感以及延时电路的组成实现了液晶显示器的背光功能


        2.此外,我们的液晶显示和键盘电路十分简洁。


         3.遗憾的是,超声波探测精度不高,准确性有待改进。


软件部分:


1.一提的是,在整个系统设计过程中,语音控制和语音输出提示一直是我


们软件设计的重点,同时也是我们的亮点,体现了我们设计系统人性化的一面。


2.键盘扫描和液晶驱动工程中,我们详尽地应用了科学的软件设计思想,


使程序简洁,有效。


3.此外,我们的主程序设计,结构鲜明,条理清晰。


4.但是,美中不足的是,我们在开启语音功能时,系统时钟不断变化,所以造成键盘扫描的不成熟,此处有待改进。


7.系统设计过程中的实践体验


            通过对该系统的设计,我们不仅收获颇丰,而且体会也颇深。


1.过这次设计,我们深深体会到,理论指导着实践,但实践才是最终的目


标。我们在设计过程中,往往遇到这样的情况,设计的电路从理论上毫无差错,但实现起来却是困难重重。只有在不断的摸索中才能找到界却问题的方法。


2.们深深体会到团体合作,在项目制作过程中十分重要,好的合作精神需


要我们时时刻刻牢记在心。


3.在任何时候,科技离不开创新,在设计项目的同时,我们需要抛弃成见,标新立异,敢于实现。在这一点上,我认为我们做得比较成功。在设计系统初始,我们采用51系列单片机,而语音功能却只能外扩专用芯片,实现起来比较困难,最后我们大胆采用凌阳单片机一举解决语音控制问题。


制作过程中,<?xml:namespace prefix = st1 ns = "urn:schemas-microsoft-com:office:smarttags" />齐明老师在技术上给予极大的帮助和支持。在此,感谢齐明老师对我们电子制作的指导!


        总之,这次活动给我们带来了无穷的收获和乐趣,感谢学校和老师给我们提供了一个锻炼的大舞台。


8.参考文献


《凌阳十六位单片机应用教程》


MCS-51 单片机应用设计》


《元器件手册》


9.附录


附录(一):凌阳单片机最小系统:



附录(二):凌阳单片机下电子锁程序实现:


#include "bsrsd.h"


#define HaveKey  1


#define NoKey    0


#define NAME_ID         0x100


#define RSP_AGAIN             1


#define RSP_NOVOICE        2


#define RSP_NAMEDIFF      3


#define RSP_CMDDIFF        4


#define RSP_STAR       5


#define RSP_NOISY              6


//宏定义


#define HaveKey 1


#define NoKey 0


//..................全程变量....................


extern void ClearWatchDog();


int PlayFlag = 0;


unsigned int Key_Value;


unsigned int  KeyDownTimes;                                //保存按键次数


                                     //按键标识


/*****************************************************************************************************/


//函数声明


void Clear_Password();


unsigned int F_Affirm_New_Password();


unsigned int F_Affirm_Password();


void Save_New_Pwd_To_Flash();


void LCD_SHOW(char Sentence[]);


void PlayRespond(int Result);


int TrainWord(int WordID, int RespondID);


//全局变量定义


extern Pwd_Init[1];


unsigned int Password[4];


unsigned int Password_Temp[4];


unsigned int Key_Flag=0;


unsigned int Key_Num=0;


unsigned int Trained="0";


/****************************************************************************************************/


main()


{


       int res, timeCnt = 0, random_no = 0,Error_No=0,NoKey_Times=10;


       int i;


       intPass=0;


/*****************************************************************************************************/   


       //变量定义


       unsigned State="1",Voice_State=0;   //这个变量用于判断目前除在哪中输入状态中


                            //1:普通开门状态   2:更改密码,输入原密码状态  3:更改密码,第一次输入新密码状态


                            //4:更改密码,第二次输入新密码状态  5:进入语音系统时输入密码状态 6:进入语音系统重新训练


                            //   输入密码验证


 


/*****************************************************************************************************/   


       Protect_Clock();


       InitIO();//键盘


       KeyDownTimes = 0;                                    


       Key_Flag = NoKey;


       ClearWatchDog();


       BSR_DeleteSDGroup(0);                                           // 初始化存储器RAM


       LCD_INIT();


       INIT_GONGNENG();    


       Clear_Password();


       LCD_SHOW("Welcome!");


       SET_Address2();


       LCD_SHOW("A?B?C?D?E?F?...");


       if(F_FlashRead(Pwd_Init))


       {


              F_FlashErase(0xfe00);


              for(i = 0;i<4;i++)


                     {


                            F_FlashWrite1Word(0xfe00+i,i);


                     }


              F_FlashWrite1Word(Pwd_Init,0);


       }


     while(1)


         {


            ClearWatchDog();


              Protect_Clock();


              InitIO();//键盘


              if(Voice_State)


              {


          Protect_Clock_fast();                                                        


              }


              else


              {


         Protect_Clock();                                                                


              }


           F_Key_Scan();


              while(Key_Flag == HaveKey)       //有按键按下


              {                  


                Key_Value=F_Get_Key() ;


                if(Voice_State==0)


                {


                  while(NoKey_Times!=0)


                  {


                        F_Key_Scan();


                        if(Key_Flag==NoKey)


                                NoKey_Times--;


                        else NoKey_Times=10;       


                  }


                     NoKey_Times=10;


                     }


                     LCD_LIGHT_OPEN();                        //打开背光功能


                   Key_Flag = NoKey; 


                     switch(Key_Value)    //判断键值


                     {    


                            //0~9表示输入的是密码,将等待下一个键的输入


                            case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 7: case 8: case 9:


                                   if(Key_Num == 0)


                                   {


                                          LCD_CLEAR();


                                          LCD_SHOW("Password:");


                                          SET_Address2();


                                   }


                                   if(Key_Num < 4)


                                   {


                                          Password[Key_Num ++] = Key_Value;                            //保存输入的键值,已输入按键数加一


                                         LCD_ADD(Key_Value+'0');                                             //屏幕上显示一个*


                                         DELAY();                                      


                                   }


                                   if(Key_Num>4)


                                   {


                                    Key_Num ++;


                                    LCD_ADD('*');


                                    DELAY();


                                   }


                                   break;


                            case 10://6:进入语音系统重新训练输入密码验证


                                          LCD_CLEAR();


                                          LCD_SHOW("Train the voice!");


                                          SET_Address2();


                                          LCD_SHOW("Check you ID:");


                                          PlayRespond(6);                             //语音提示****"请输入密码---------(6)"!·!!!!!


                                          Protect_Clock();


                                          State=6;


                                          Key_Num =0;


                                          break;


                            case 11://确认键


                                          //输入新密码时的两个状态处理方式有所不同


                                   if(State ==    3)


                                   {


                                          if(Key_Num == 4)


                                          {


                                                 LCD_CLEAR();


                                                 LCD_SHOW("Please Again!");


                                                 SET_Address2();


                                                 LCD_SHOW("Input new PWD:");


                                                 PlayRespond(8);                             //语音提示*****“请再次输入新密码---------(7)“!·!!!!!


                                                 Protect_Clock();                                           


                                                 for(i = 0;i<4;i++) /*把这个密码存到临时变量Password_Temp*/


                                                 {


                                                        Password_Temp=Password;


                                                 }


                                                 Pass=0;


                                                 Key_Num =0;


                                                 State = 4;


                                                 break;


                                          }


                                          else


                                          {    


                                                 LCD_CLEAR();


                                                 LCD_SHOW("4 bit PSW!");


                                                 SET_Address2();


                                                 LCD_SHOW("Please Again!");


                                                


                                                 PlayRespond(7);                             //语音提示*****“密码错误------(3)”!·!!!!!


                                                 Protect_Clock();                      


                                                 LCD_CLEAR();


                                                 LCD_SHOW("Welcome!");


                                                 SET_Address2();


                                                 LCD_SHOW("A?B?C?D?E?F?...");


                                                 Key_Num =0;


                                                 State = 1;


                                                 break;


                                          }


                                   }


                                   else if(State == 4)


                                          {Pass=0;


                                          Pass = F_Affirm_New_Password();


                                          }     //第二遍输入密码时的验证


                                   else


                                          {Pass=0;


                                          Pass = F_Affirm_Password(); 


                                          } //验证密码


                                         


                                   if(Pass == 1) //密码正确


                                   {


                                   //判断目前状态,确定这个正确的密码是用来干吗的


                                          Pass = 0;


                                          Error_No=0;


                                          LCD_LIGHT_OFF();


                                          switch(State)


                                          {


                                                 case 1:


                                                        DOOR_OPEN();/*开门*/


                                                        LIGHT_OPEN();


                                                        LCD_CLEAR();


                                                        LCD_SHOW("DOOR OPENED");


                                                        PlayRespond(12);                                  //语音提示*****“主人您好,门已经开了(!·!!!!!


                                                        Protect_Clock();


                                                        SET_Address2();


                                                        LCD_SHOW("Best Wishes!");


                                                        DOOR_OFF();


                                                        LIGHT_OFF();


                                                        LCD_CLEAR();


                                                        LCD_SHOW("Welcome!");


                                                        SET_Address2();


                                                        LCD_SHOW("A?B?C?D?E?F?...");


                                                        Key_Num=0;


                                                        State = 1;


                                                        break;


                                                 case 2:


                                                


                                                        LCD_CLEAR();


                                                        LCD_SHOW("Password right!");


                                                        SET_Address2();


                                                        LCD_SHOW("New password:");


                                                       


                                                        PlayRespond(8);                             //语音提示*****请输入新密码!·!!!!!


                                                        Protect_Clock();


                                                        State = 3;


                                                        break;


                                                 case 4:


                                                        Save_New_Pwd_To_Flash();         // 保存新密码


                                                        LCD_CLEAR();


                                                        LCD_SHOW("Successfully!");


                                                        SET_Address2();


                                                        LCD_SHOW("Remenber The New");


                                                        PlayRespond(9);                             //语音提示*****密码修改成功,要记住哦!·!!!!!


                                                        Protect_Clock();


                                                        LCD_CLEAR();


                                                        LCD_SHOW("Welcome!");


                                                        SET_Address2();


                                                        LCD_SHOW("A?B?C?D?E?F?...");


                                                        State = 1;


                                                        break;


                                                 case 5:


                                                        if(Trained)


                                                        {


                                                               Voice_State=1;


                                                        }


                                                        else


                                                        {


                                                               while(TrainWord(NAME_ID,0) != 0) ;         


                                                               BSR_InitRecognizer(BSR_MIC);                          //辨识器初始化


                                                               Protect_Clock();                                                   //******保护时钟************************


                                                               BSR_EnableCPUIndicator();                       //启动实时监控


                                                                                                                                    


                                                               PlayRespond(RSP_STAR);                                           //*******播放开始辨识的提示音                 


                                                               Protect_Clock();                                                   //******保护时钟************************


                                                               Trained = 1;


                                                               Voice_State=1;


                                                        }


                                                        LCD_CLEAR();


                                                        LCD_SHOW("Voice on");


                                                        SET_Address2();


                                                        LCD_SHOW("Remember it!");


                                                        PlayRespond(13);                                  //语音提示*****语音功能已经开启!·!!!!!


                                                        Protect_Clock();


                                                        LCD_CLEAR();


                                                        LCD_SHOW("Welcome!");


                                                        SET_Address2();


                                                        LCD_SHOW("A?B?C?D?E?F?...");


                                                        State=1;


                                                        break;                                             


                                                 case 6://重新输入开始语音训练


                                                        Trained=0;


                                                        if(Trained)


                                                        {


                                                               Voice_State=1;


                                                        }


                                                        else


                                                        {


                                                               BSR_DeleteSDGroup(0);                                           // 初始化存储器RAM


                                                               while(TrainWord(NAME_ID,0) != 0) ;         


                                                               BSR_InitRecognizer(BSR_MIC);                          //辨识器初始化


                                                               BSR_EnableCPUIndicator();                       //启动实时监控


                                                               PlayRespond(RSP_STAR);                                           //播放开始辨识的提示音


                                                               Protect_Clock();


                                                               Trained = 1;


                                                               Voice_State=1;


                                                        }


                                                        LCD_CLEAR();


                                                        LCD_SHOW("Voice Trained!");


                                                        SET_Address2();


                                                        LCD_SHOW("Remember it!");


                                                        PlayRespond(9);                             //语音提示*****语音密码修改成功!·!!!!!


                                                        Protect_Clock();


                                                        InitIO();//键盘


                                                        KeyDownTimes = 0;                                    


                                                        Key_Flag = NoKey;


                                                        //BSR_DeleteSDGroup(0);                                                // 初始化存储器RAM


                                                        LCD_INIT();


                                                        INIT_GONGNENG();


                                                        LCD_CLEAR();


                                                        LCD_SHOW("Welcome!");


                                                        SET_Address2();


                                                        LCD_SHOW("A?B?C?D?E?F?...");


                                                        State=1;                                          


                                                        break;                                                                                                                                                                                         


                                                 default:


                                                        break;


                                          }            //Switch(State)


                                          Clear_Password();


                                          Key_Num=0;


                                          break;


                                   }            //if(pass==1)


                                   else


                                   {    


                                          Error_No++;


                                          if(Error_No<3)


                                          {


                                           LCD_CLEAR();


                                           LCD_SHOW("error pwd");


                                           SET_Address2();


                                           LCD_SHOW("Remember it!");


                                          PlayRespond(7);                             //语音提示*****密码错误!·!!!!!


                                          Protect_Clock();


                                           LCD_CLEAR();                                        


                                         LCD_SHOW("Welcome!");


                                       SET_Address2();


                                           LCD_SHOW("A?B?C?D?E?F?..");


                                          }


                                          else


                                          {


                                           LCD_CLEAR();


                                           LCD_SHOW("error pwd");


                                           SET_Address2();


                                        LCD_SHOW("Remember it!");


                                           ALARM();


                                                                                    


                                           PlayRespond(10);                                //语音提示*****我要报警了!!!!·!!!!!


                                           Protect_Clock();


                                                                                                                      


                                           LCD_CLEAR();                                        


                                         LCD_SHOW("Welcome!");


                                       SET_Address2();


                                           LCD_SHOW("A?B?C?D?E?F?..");


                                          }


                                                                            


                                          Clear_Password();


                                          Key_Num=0;


                                          State = 1;


                                          break;


                                   }


                            case 12://取消键


                                  


                                   LCD_CLEAR();


                                   LCD_SHOW("Cancel");


                                   SET_Address2();


                                   LCD_SHOW("Do it again!");


                                   Clear_Password();


                                   LCD_CLEAR();                                   


                                   LCD_SHOW("Welcome!");


                                   SET_Address2();


                                   LCD_SHOW("A?B?C?D?E?F?..");


                                  


                                   Key_Num=0;


                                   State = 1;


                                   break;


                            case 13://更改键


                                   LCD_CLEAR();


                                   LCD_SHOW("Modify passwd!");


                                   SET_Address2();


                                   LCD_SHOW("Check you ID:");


                                   PlayRespond(6);                             //语音提示****"请输入密码"!·!!!!!


                                   Protect_Clock();                                                         


                                   State = 2;


                                   break;


                            case 14://进入语音


                                   LCD_CLEAR();


                                   LCD_SHOW("Open voice!");


                                   SET_Address2();


                                   LCD_SHOW("Check you ID:");


                                                


                                   PlayRespond(6);                             //语音提示****"请输入密码"!·!!!!!


                                   Protect_Clock();                                                         


                           


                                   State = 5;


                                   break;   


                            case 15://关闭语音


                                   LCD_CLEAR();


                                   LCD_SHOW("VOICE OFF");


                                   SET_Address2();


                                   LCD_SHOW("Remember it!");


 


                                   Voice_State=0;


                                   PlayRespond(11);                                   //语音提示****"语音功能关闭!·!!!!!


                                   Protect_Clock();                                                                       


                                   LCD_CLEAR();                                   


                                   LCD_SHOW("Welcome!");


                                   SET_Address2();


                                   LCD_SHOW("A?B?C?D?E?F?..");


                                   break;


                            default   :


                                   break;


                     }//switch(KeyValue)相对应


      }//while(有键按下)


      if(Voice_State)


      {


        Protect_Clock_fast();


        res = ProtectA_BSR_GetResult();   


              Protect_Clock();                                                                                            


              if(res > 0)                                                 //识别出命令


              {


                            switch(res)


                            {


                            case NAME_ID:                 //触发命令响应


                                                        DOOR_OPEN();/*开门*/


                                                        LIGHT_OPEN();


                                                       


                                                        LCD_CLEAR();


                                                        LCD_SHOW("DOOR OPENED");


                                                        PlayRespond(12);                                  //语音提示*****“主人您好,门已经开了!·!!!!!                                                 


                                                        Protect_Clock();                                                  


                                                        SET_Address2();


                                                        LCD_SHOW("Best Wishes!");


                                                        DOOR_OFF();


                                                        LIGHT_OFF();


                                                        LCD_CLEAR();


                                                        LCD_SHOW("Welcome!");


                                                        SET_Address2();


                                                        LCD_SHOW("A?B?C?D?E?F?...");


                                                        Key_Num=0;//**********?


                                                        State = 1;//********?


                                                break;


                           }


             }


         }//if(Voice_state=1)


     


}//while(1)


}//main()


 


///////////////////////////////////////////////


void Clear_Password()


{


       int i;


       for(i = 0;i<4;i++)


       {


              Password = 0;


              Password_Temp = 0;


       }


       Key_Num = 0;


}


/////////////////////////////////////////////////


 


unsigned int F_Affirm_New_Password()


{


       int i;


       for(i=0;i<4;i++)


       if(Password!=Password_Temp)


              {return 0;}


      


       return 1;


}


///////////////////////////////////////////////////


unsigned int F_Affirm_Password()


{


       int i;


       unsigned temp;


       for(i=0;i<4;i++)


       {


              temp = F_FlashRead(0xfe00 + i);             //确定返回值是r1


              if(


              Password != temp)


              return 0;


       }


       return 1;


}


/////////////////////////////////////////////////////


void Save_New_Pwd_To_Flash()


{


       int i;


       F_FlashErase(0xfe00);


 


       for(i=0;i<4;i++)


       {


              F_FlashWrite1Word(0xfe00+i,Password);


       }


}


///////////////////////////////////////////////////////


void LCD_SHOW(char Sentence[])


{


       int i;


       for(i=0; Sentence != '\0'; i++)


              LCD_ADD(Sentence);


}


////////////////////////////////////////////////////////


void PlayRespond(int Result)


{


       BSR_StopRecognizer();


       SACM_S480_Initial(1);


       SACM_S480_Play(Result, 3, 3);


       while((SACM_S480_Status()&0x0001) != 0)


       {


              SACM_S480_ServiceLoop();


              ClearWatchDog();


       }


       SACM_S480_Stop();


       BSR_InitRecognizer(BSR_MIC);


       BSR_EnableCPUIndicator(); 


}


////////////////////////////////////////////////////////


int TrainWord(int WordID, int RespondID)


{


       int res;


       PlayRespond(RespondID);//----------------------------------请输入触发名称-     0-----------


       while(1)


       {    


              ClearWatchDog();


             


              Protect_Clock_fast();


              res = BSR_Train(WordID,BSR_TRAIN_TWICE);


              Protect_Clock();


             


              if(res == 0) break;


              switch(res)


              {


              case -1:                                                                //没有检测出声音-----------1


                     PlayRespond(RSP_NOVOICE);


                     return -1;


              case -2:                                                                //需要重新训练一遍-----2


                     PlayRespond(RSP_AGAIN);


                     break;


              case -3:                                                                //环境太吵--------3


                     PlayRespond(RSP_NOISY);


                     return -1;            


              case -4:                                                                //数据库满


                    return -1;


              case -5:                                                                //检测出声音不同


                     if(WordID == NAME_ID)      PlayRespond(RSP_NAMEDIFF);//两次输入名称不同(4


                     else                             PlayRespond(RSP_CMDDIFF);//两次输入命令不同(5


                     return -1;


              case -6:                                                                //序号错误


                     return -1;


              }


       Protect_Clock();


       }


       return 0;


       Protect_Clock();


}


附录(三):器件列表


 


凌阳单片机最小系统一套;


16*2 16位液晶显示器一块;


4*4键盘一个;


C945 三极管若干;


继电器一块;


555定时器若干;


超声波探头一对;


LM567音频解码器一个;


电阻电容若干;


74LS00与非门一块;

PARTNER CONTENT

文章评论0条评论)

登录后参与讨论
EE直播间
更多
我要评论
0
3
关闭 站长推荐上一条 /3 下一条