毕业设计基于AT89S52单片机的电子密码锁控制系统设计

上传人:仙*** 文档编号:79436132 上传时间:2022-04-23 格式:DOC 页数:31 大小:2.28MB
返回 下载 相关 举报
毕业设计基于AT89S52单片机的电子密码锁控制系统设计_第1页
第1页 / 共31页
毕业设计基于AT89S52单片机的电子密码锁控制系统设计_第2页
第2页 / 共31页
毕业设计基于AT89S52单片机的电子密码锁控制系统设计_第3页
第3页 / 共31页
点击查看更多>>
资源描述
盐城工学院课程设计说明书(2012)单片机课程设计说明书 电子密码锁控制系统设计专业电气工程及其自动化学生姓名张思雨班级B电气094学号0910601410指导教师张兰红完成日期2012年 6月10日目录1 课题设计目标22 总体设计方案22.1 设计思路22.2 方案确立23 硬件电路方框图23.1 单片机及其最小系统33.1.1 复位电路的设计33.1.2时钟电路的设计33.2 密码锁电路43.2.1 按键电路的设计43.2.2 LCD显示电路54 程序设计74.1 模块介绍75 课程设计总结86 参考文献97 附 录10附录一 总电路原理图10附录二:电子密码锁的PCB图11附录三:电子密码锁的实物图12附录四:元器件清单14附录五 源程序清单151 课题设计目标本设计采用MCS-51系列单片机AT89S52作为主控芯片,结合外围电路,设计密码锁控制系统,能够实现:2 总体设计方案2.1 设计思路该电路是一种采用以AT89S52为核心的单片机控制方案。利用单片机灵活的编程设计和丰富的IO端口,及其控制的准确性,不但能实现基本的密码锁功能,还能根据实际需要添加调电存储、声光提示功能。2.2 方案确立(1)为了实现密码的保密性,采用一个44的矩阵式键盘可以任意设置用户密码,从而提高了密码的保密性。(2)采用LCD显示单元,提高了可读性 ,提供良好的人机界面。3 硬件电路方框图电路由两大部分组成:AT89S51单片机及其外围电路和密码锁电路。密码锁电路包含:矩阵键盘输入、LCD指示电路、报警控制电路、AT24C02掉电存储电路。其原理方框图如图3.1所示。图3.1 系统结构框图3.1 单片机及其最小系统3.1.1 复位电路的设计复位是单片机的初始化操作。单片机启运运行时,都需要先复位,其作用是使CPU和系统中其他部件处于一个确定的初始状态,并从这个状态开始工作。因而,复位是一个很重要的操作方式。但单片机本身是不能自动进行复位的,必须配合相应的外部电路才能实现。该复位电路采用按键电平复位式复位电路。当单片机已在运行当中时,按下复位键S后松开,在复位引脚RET(9脚)脚持续出现24个振荡器脉冲周期(即2个机器周期)的高电平信号将使单片机复位。也能使RST为一段时间的高电平,从而实现上电或开关复位的操作。如图3.2所示。图3.2 复位电路3.1.2时钟电路的设计时钟电路为单片机产生时序脉冲,单片机所有运算与控制过程都是在统一的时序脉冲的驱动下的进行的,如果单片机的时钟电路停止工作(晶振停振),那么单片机也就停止运行了。当采用内部时钟时,连接方法如下图所示,在晶振引脚XTAL1(19脚)和XTAL2(18脚)引脚之间接入一个11.0592MHZ晶振,两个引脚对地分别再接入一个电容即可产生所需的时钟信号,电容的容量一般在几十皮法,如20PF。如图3.3所示。图3.3 时钟电路3.2 密码锁电路3.2.1 按键电路的设计 为了加强密码的保密性,采用一个44的矩阵式键盘可以任意设置用户密码(1-16位长度),从而提高了密码的保密性,同时也能减少与单片机接口时所占用的I/O口线的数目,节省了单片机的宝贵资源,在按键比较多的时候,通常采用这种方法。其原理图如图3.4所示。图3.4 矩阵键盘电路每一行与每一列的交叉处不相同,而是通过一个按键来连通,利用这种行列式矩阵结构只需要N根行线与M根列线,即可组成具有N M 个按键的矩阵键盘。在这种行列式矩阵键盘编码的单片机系统中,键盘处理程序首先执行等待按键并确认有无按键按下的程序段。当确认有按键按下后,下一步就是要识别哪一个按键被按下。对键的识别方法通常有两种:一种是通用的组行扫描查询法;另一种是速度较快的线反转法。此系统中,我们采用线反转法。首先辨别键盘中有无按键被按下,在单片机I/O口向键盘送全扫描字,然后读入行线状态来判断。具体方法是:向行线输出全扫描字00H,把全部列线置成低电平,然后将列线的电平状态读入累加器A中。如果有按键被按下,总会有一根行线电瓶被拉至低电平从而使行线不全为1。判断键盘中哪一个按键被按下通常是通过将列线逐列至低电平后,检查行输入状态来实现的。方法是:依次给列线送低电平,然后检查所有行线状态,如果全为1,则所按下的按键不在此列;如果不全为1,则所按下的按键必在此列,而且是在与零电平行线相交的交点上的那个按键。10个数字键用来输入密码,另外2个功能键分别是:确认、取消。其中退格键的功能是当输入密码错误的时候,清除前面已经输入的数据,重新输入。确认键的功能是确认输入的密码。按键功能表按键键名功能说明0-9键数字键输入密码E键确认确认密码F键退格退出3.2.2 LCD显示电路本系统设计的显示电路是为了给使用者以提示而设置的。因为系统具有账户管理系统,使用LCD可以为用户提供更友好的人机界面,故选用LCD1602作为显示器件。开锁时,按下键盘上的开锁按键后,利用键盘上的数字键09输入密码,每按下一个数字键后在显示器上显示一个*,输入多少位就显示多少个*。当密码输入完成时,按下确认键,如果输入的密码正确的话, LCD显示“”,单片机其中P3.0引脚会输出低电平,使三极管T2导通,电磁铁吸合,继电器开关跳转,电子密码锁被打开,如果密码不正确,LCD显示屏会显示“nter please”,P3.0输出的是高电平,电子密码锁不能打开。通过LCD显示屏,可以清楚地判断出密码锁所处的状态。图3.5 显示器电路显示器主要用于显示以下几个字符,指示如图3.6所示。eAloWHl图3.6(a) 开机状态rnepleDaseEt图3.6(b) 等待输入状态OK图3.6 (c) 密码输入正确状态4 程序设计4.1 模块介绍本设计将密码锁软件分为以下几个模块(程序见附录程序清单):(1)主程序模块主程序主要完成系统及外围电路的初始化,控制LCD根据按键操作进行各个状态的转化,实现密码锁的人机交互界面。(2)键盘驱动及键盘输入程序主要包括键盘扫描的程序,根据按键的布局进行符合操作习惯的键值映射,键盘操作到数据的转换。(3)LCD1602驱动包括液晶屏的初始化程序和字符显示,字符串显示等基本函数,供主程序调用(4)AT24C02存取程序包括I2C总线的读写时序模拟控制及读写程序主程序流程图如图4.1所示:图4.1 主程序流程图5 课程设计总结在做本次课程设计的过程中,我感触最深的当属查阅大量的设计资料了。为了让自己的设计更加完善,查阅这方面的设计资料是十分必要的,同时也是必不可少的。我们是在做单片机课程设计,但我们不是艺术家,他们可以抛开实际尽情在幻想的世界里翱翔,而我们一切都要有据可依,有理可寻,不切实际的构想永远只能是构想,永远无法升级为设计。其次,在这次课程设计中,我们运用到了以前所学的专业课知识,如:protel99制图,C语言等。虽然过去从未独立应用过它们,但在学习的过程中带着问题去学我发现效率很高,这是我做这次课程设计的又一收获。最后,要做好一个课程设计,就必须做到:在设计程序之前,对所用单片机的内部结构有一个系统的了解,知道该单片机内有哪些资源;要有一个清晰的思路和一个完整的的软件流程图;在设计程序时,不能妄想一次就将整个程序设计好,反复修改、不断改进是程序设计的必经之路;要养成注释程序的好习惯,一个程序的完美与否不仅仅是实现功能,而应该让人一看就能明白你的思路,这样也为资料的保存和交流提供了方便;在设计课程过程中遇到问题是很正常德,但我们应该将每次遇到的问题记录下来,并分析清楚,以免下次再碰到同样的问题。另外,这次课程设计让我感到了团队合作的重要性。在团队中,我们互帮互助,对整个课程设计来说,这是至关重要的,缺少每一个人都会对我们的设计产生影响。还有要感谢指导老师在我们遇到困难时,给予我们的建议与鼓励。几周的课程设计结束了,但是从中学到的知识会让我受益终身。发现、提出、分析、解决问题和实践能力的提高都会受益于我在以后的学习、工作和生活中。6 参考文献1 张天凡. 完全手册-51单片机C语言开发详解M.电子工业出版社,20082 李群芳. 单片微型计算机与接口技术M.北京:电子工业出版社,20083 赵景波. Protel DXP实用教程M.人民邮电出版社,20094 丁明亮,唐前辉. 51单片机应用设计与仿真-基于Keil C与ProteusM. 北京航空航天大学出版社,20095 Atmel.AT89S51 Data Sheet6 ShareWave.LCD1602器件手册7 Atmel. AT24C02 Data Sheet7 附 录附录一 总电路原理图附录二:电子密码锁的PCB图附录三:电子密码锁的实物图附录四:元器件清单名称型号数量备注单片机AT89S521含双列直插插座电阻10K6电阻2202排阻8x10k1液晶显示器LM16021瓷片电容33pF2电解电容10uF1按键轻触按键16晶振11.0592MHz1单排插针1x84发光二极管2直流插座1下载口1继电器1附录五 源程序清单#include #define uint unsigned int#define uchar unsigned char#define KEY P1 /键盘输入端口#define No_key 20 /无按键时的返回值#define lcddata P0 /1602的数据输入端口sbit lcden= P22;sbit lcdrs= P20;sbit lcdrw= P21;sbit light= P30;sbit light1= P31;uchar j ; /用来统计输入 个数的全局变量uchar aa; /用来在定时器中计数的 全局变量 uchar code table= Hello!;uchar code table1= OK! ;uchar code table2=Enter please: ;uchar code key_table16 = 1,2,3,10, 4,5,6,11, 7,8,9,12, 0,13,14,15 ;uchar password=2,0,1,0,9,3 ; /设定初始密码uchar save6; /保存输入的数据uchar conflag ; /确认标志uchar lockflag; /锁键盘标志uchar startflag; /开始标志 void delay(uint z); /延时子函数void wright_com(uchar com); /写指令函数void wright_data(uchar date) ; /写数据函数void init(); /初始化void display_OK(); / 显示OKvoid delete(); /删除输入的最后一个数uchar keyscan() ; /带返回值的键盘扫描程序void enter_code(uchar t); /输入密码函数,把输入的数据存入数组中并在屏幕上显示相应的东西,void confirm(); /确认密码对不对,把输入的数据与密码逐一对比,完全一样刚正确,void succeed_an(); /输入密码成功时的 响应,void fail_an(); /输入密码 失败时 响应 void lockkey(); /锁键盘三秒void reset(); /复位函数void display_enter(); /显示输入void main(void) uchar temp; init(); while(1) if(lockflag) temp=keyscan(); / 锁键期间也要进行键盘扫描 if(temp!=No_key) /重新记时三秒 aa=0; /重新在定时器中计数 else temp=keyscan(); /反复扫描输入,等待随时输入 if(temp!=No_key) /有按键按下才进行下面的操作 if(temp=10) reset(); startflag=1; /开始标志置位 if(startflag) enter_code(temp); /每扫描一次键盘就要进行一次处理,保存输入的数值 if(temp=13) /按下确认键盘就要进行密码确认 confirm(); /进行确认判断 if(conflag) /密码确认为正确 succeed_an(); /密码正确,作出相应的反应 else fail_an(); /密码错误,作相应反应 if(temp=14) delete(); /作删除操作 /* 显示enter*/void display_enter() uchar num; wright_com(0x80);for(num=0;num13;num+) wright_data(table2num); /* 显示OK*/void display_OK() uchar num;wright_com(0x80);for(num=0;num13;num+) wright_data(table1num); /* 删除最后一个*/void delete() wright_com(0x80+0x40+j); /确定删除对象wright_data( ); /显示空格即为删除save-j=0; /删除后数据清零wright_com(0x80+0x40+j); /为下次输入数据时写好位置,必须是在最后一个后面/* 对各种变量进行复位*/void reset()uchar num;display_enter();wright_com(0x80+0x40); /擦除屏幕上的显示for(num=0;num=0&t10) if(j=0) wright_com(0x80+0x40) ; /第一输入时要先写入地址指令,否则无法显示 wright_data(*) ; else wright_data(*) ;/不是第一个输入则不用再写地址 savej+=t; /保存输入的数据 /*校对密码以确定是不是正确的*/void confirm()uchar k;for(k=0;k=60) /三秒到了 aa=0; /清零可以方便下次再使用 light1=1; /关闭警报 lockflag=0; /标志清零解除键锁,方便下次使用 /*初始化*/void init() uchar num; /*定时器初始化*/ TMOD=1;TH0=(65536-50000)/256;TL0=(65536-50000)%256;ET0=1;EA=1; /开启总中断TR0=1;/把定时器关闭/*1602初始化*/lcdrw=0; /这个必须要置 零,否则无法正常显示 lcden=0;wright_com(0x38) ; /初始化 wright_com(0x0c) ; /打开光标 0x0c不显示光标 0x0e光标不闪,0x0f光标闪wright_com(0x01) ; /清显示wright_com(0x80) ;for(num=0;num0;x-) for(y=110;y0;y-) ;/*4x4矩阵键盘扫描函数*/uchar keyscan() uchar temp,num=No_key; /num的初值要为无键盘按下时的返回值/*扫描第一行*/ KEY=0xfe; temp=KEY; temp=temp&0xf0; /读出高四位 while(temp!=0xf0) delay(5); /延时消抖 temp=KEY; temp=temp&0xf0; while(temp!=0xf0) /确认确实有按键按下 temp=KEY; switch(temp) /根据这八个电平可以确定是哪个按键按下 case 0xee:num=1; break; case 0xde:num=2; break; case 0xbe:num=3; break; case 0x7e:num=10; break; while(temp!=0xf0) /等待松手 temp=KEY; temp=temp&0xf0; /*扫描第二行*/ KEY=0xfd; temp=KEY; temp=temp&0xf0; while(temp!=0xf0) delay(5); temp=KEY; temp=temp&0xf0; while(temp!=0xf0) temp=KEY; switch(temp) case 0xed:num=4; break; case 0xdd:num=5; break; case 0xbd:num=6; break; case 0x7d:num=11; break; while(temp!=0xf0) temp=KEY; temp=temp&0xf0; /*扫描第三行*/ KEY=0xfb; temp=KEY; temp=temp&0xf0; while(temp!=0xf0) delay(5); temp=KEY; temp=temp&0xf0; while(temp!=0xf0) temp=KEY; switch(temp) case 0xeb:num=7; break; case 0xdb:num=8 ; break; case 0xbb:num=9; break; case 0x7b:num=12; break; while(temp!=0xf0) temp=KEY; temp=temp&0xf0; /*扫描第四行*/ KEY=0xf7; temp=KEY; temp=temp&0xf0; while(temp!=0xf0) delay(5); temp=KEY; temp=temp&0xf0; while(temp!=0xf0) temp=KEY; switch(temp) case 0xe7:num=0; break; case 0xd7:num=13; break; case 0xb7:num=14; break; case 0x77:num=15; break; while(temp!=0xf0) temp=KEY; temp=temp&0xf0; return num;g an employment tribunal claiEmployment tribunals sort out disagreements between employers and employees.You may need to make a claim to an employment tribunal if: you dont agree with the disciplinary action your employer has taken against you your employer dismisses you and you think that you have been dismissed unfairly.For more information about dismissal and unfair dismissal, seeDismissal.You can make a claim to an employment tribunal, even if you haventappealedagainst the disciplinary action your employer has taken against you. However, if you win your case, the tribunal may reduce any compensation awarded to you as a result of your failure to appeal.Remember that in most cases you must make an application to an employment tribunal within three months of the date when the event you are complaining about happened. If your application is received after this time limit, the tribunal will not usually accept i.If you are worried about how the time limits apply to you, take advice from one of the organisations listed underFurther help.Employment tribunals are less formal than some other courts, but it is still a legal process and you will need to give evidence under an oath or affirmation.Most people find making a claim to an employment tribunal challenging. If you are thinking about making a claim to an employment tribunal, you should get help straight away from one of the organisations listed underFurther help.If you are being represented by a solicitor at the tribunal, they may ask you to sign an agreement where you pay their fee out of your compensation if you win the case. This is known as adamages-based agreement. In England and Wales, your solicitor cant charge you more than 35% of your compensation if you win the case.If you are thinking about signing up for a damages-based agreement, you should make sure youre clear about the terms of the agreement. It might be best to get advice from an experienced adviser, for example, at a Citizens Advice Bureau. To find your nearest CAB, including those that give advice by e-mail, click onnearest CAB.For more information about making a claim to an employment tribunal, seeEmployment tribunals.The (lack of) air up there Watch mCayman Islands-based Webb, the head of Fifas anti-racism taskforce, is in London for the Football Associations 150th anniversary celebrations and will attend Citys Premier League match at Chelsea on Sunday.I am going to be at the match tomorrow and I have asked to meet Yaya Toure, he told BBC Sport.For me its about how he felt and I would like to speak to him first to find out what his experience was.Uefa hasopened disciplinary proceedings against CSKAfor the racist behaviour of their fans duringCitys 2-1 win.Michel Platini, president of European footballs governing body, has also ordered an immediate investigation into the referees actions.CSKA said they were surprised and disappointed by Toures complaint. In a statement the Russian side added: We found no racist insults from fans of CSKA.Age has reached the end of the beginning of a word. May be guilty in his seems to passing a lot of different life became the appearance of the same day; May be back in the past, to oneself the paranoid weird belief disillusionment, these days, my mind has been very messy, in my mind constantly. Always feel oneself should go to do something, or write something. Twenty years of life trajectory deeply shallow, suddenly feel something, do it.一字开头的年龄已经到了尾声。或许是愧疚于自己似乎把转瞬即逝的很多个不同的日子过成了同一天的样子;或许是追溯过去,对自己那些近乎偏执的怪异信念的醒悟,这些天以来,思绪一直很凌乱,在脑海中不断纠缠。总觉得自己自己似乎应该去做点什么,或者写点什么。二十年的人生轨迹深深浅浅,突然就感觉到有些事情,非做不可了。The end of our life, and can meet many things really do?而穷尽我们的一生,又能遇到多少事情是真正地非做不可?During my childhood, think lucky money and new clothes are necessary for New Year, but as the advance of the age, will be more and more found that those things are optional; Junior high school, thought to have a crush on just means that the real growth, but over the past three years later, his writing of alumni in peace, suddenly found that isnt really grow up, it seems is not so important; Then in high school, think dont want to give vent to out your inner voice can be in the high school children of the feelings in a period, but was eventually infarction when graduation party in the throat, later again stood on the pitch he has sweat profusely, looked at his thrown a basketball hoops, suddenly found himself has already cant remember his appearance.童年时,觉得压岁钱和新衣服是过年必备,但是随着年龄的推进,会越来越发现,那些东西根本就可有可无;初中时,以为要有一场暗恋才意味着真正的成长,但三年过去后,自己心平气和的写同学录的时候,突然就发现是不是真正的成长了,好像并没有那么重要了;然后到了高中,觉得非要吐露出自己的心声才能为高中生涯里的懵懂情愫划上一个句点,但毕业晚会的时候最终还是被梗塞在了咽喉,后来再次站在他曾经挥汗如雨的球场,看着他投过篮球的球框时,突然间发现自己已经想不起他的容颜。Originally, this world, can produce a chemical reaction to an event, in addition to resolutely, have to do, and time.原来,这个世界上,对某个事件能产生化学反应的,除了非做不可的坚决,还有,时间。A persons time, your ideas are always special to clear. Want, want, line is clear, as if nothing could shake his. Also once seemed to be determined to do something, but more often is he backed out at last. Dislike his cowardice, finally found that there are a lot of love, there are a lot of miss, like shadow really have been doomed. Those who do, just green years oneself give oneself an arm injection, or is a self-righteous spiritual.一个人的时候,自己的想法总是特别地清晰。想要的,不想要的,界限明确,好像没有什么可以撼动自己。也曾经好像已经下定了决心去做某件事,但更多的时候是最后又打起了退堂鼓。嫌恶过自己的怯懦,最终却发现有很多缘分,有很多错过,好像冥冥之中真的已经注定。那些曾经所谓的非做不可,只是青葱年华里自己给自己注射的一支强心剂,或者说,是自以为是的精神寄托罢了。At the moment, the sky is dark, the air is fresh factor after just rained. Suddenly thought of blue plaid shirt; Those were broken into various shapes of stationery; From the corner at the beginning of deep friendship; Have declared the end of the encounter that havent start planning. Those years, those days of do, finally, like youth, will end in our life.此刻,天空是阴暗的,空气里有着刚下过雨之后的清新因子。突然想到那件蓝格子衬衫;那些被折成各种各样形状的信纸;那段从街角深巷伊始的友谊;还有那场还没有开始就宣告了终结的邂逅计划那些年那些天的非做不可,终于和青春一样,都将在我们的人生中谢幕。Baumgartner the disappointing news: Mission aborted. r plays an important role in this mission. Starting at the ground, conditions have to be very calm - winds less than 2 mph, with no precipitation or humidity and limited cloud cover. The balloon, with capsule attached, will move through the lower level of the atmosphere (the troposphere) where our day-to-day weather lives. It will climb higher than the tip of Mount Everest (5.5 miles/8.85 kilometers), drifting even higher than the cruising altitude of commercial airliners (5.6 miles/9.17 kilometers) and into the stratosphere. As he crosses the boundary layer (called the tropopause),e can expect a lot of turbulence.The supersonic descent could happen as early as Sunda.The weatheThe balloon will slowly drift to the edge of space at 120,000 feet ( Then, I would assume, he will slowly step out onto something resembling an Olympic diving platform.Below, the Earth becomes the concrete bottom of a swimming pool that he wants to land on, but not too hard. Still, hell be traveling fast, so despite the distance, it will not be like diving into the deep end of a pool. It will be like he is diving into the shallow end. Skydiver preps for the big jumpWhen he jumps, he is expected to reach the speed of sound - 690 mph (1,110 kph) - in less than 40 seconds. Like hitting the top of the water, he will begin to slow as he approaches the more dense air closer to Earth. But this will not be enoug
展开阅读全文
相关资源
相关搜索

最新文档


当前位置:首页 > 办公文档


copyright@ 2023-2025  zhuangpeitu.com 装配图网版权所有   联系电话:18123376007

备案号:ICP2024067431-1 川公网安备51140202000466号


本站为文档C2C交易模式,即用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。装配图网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知装配图网,我们立即给予删除!