资源描述
山东传媒职业学院毕业论文 论文题目简要分析清除键盘机械抖动的方法 指导教师/职称 罗东华/中级讲师 作者姓名 于海洋 年级/专业 10级广播电视技术1班 山东传媒职业学院2011年 12 月 日目 录摘要1英文摘要1一.基本原理 2二消除键盘机械抖动方法实际应用情况 4三两种方法的对比总结5谢 辞 6参考文献 6清除键盘机械抖动的方法广播电视技术技术专业 一班 指导老师 罗东华 内容提要:单片机控制系统中大多使用控制键来实现控制功能,对按键处理的重要环节是去抖动,包括去除按下和抬起瞬间的抖动。消除按键瞬间的抖动是设计者必须要考虑的问题。本文通过分别分析硬件和软件两种键盘消抖的方法,使用R-S触发器的硬件方法、运用算法的软件方法,对比得出两种方法不同的优劣点。硬件方法会增加成本和体积,对于按键较多的矩阵式键盘,会用硬件方法;软件方法用的比较普遍,但有一种加固定延时的去抖动法效率最低,它以无谓地耗费机时来实现去抖动。 关键词:按键消抖;R-S触发器;软件算法Removing the keyboard mechanical dithering methodTechnology of radio and television technology Class one Instructor Luo donghuaAbstract : SCM control system mostly using the control key to realize the control function, the key processing is a important link to jitter, including the removal of pressing and lifting moment jitter. Elimination of jitter of the key moment is the designer must consider the problem. This paper analyzes the hardware and software of two keyboard shaking elimination method, using the R-S trigger hardware method, using software method, comparison between two methods of different strengths and weaknesses. The hardware method will increase the cost and volume for the key, more matrix keyboard, with hardware method; software method to use in the more common, but there is a plus fixed delay dithering method minimum efficiency, it needlessly consuming machine to achieve jitter. Key words: button buffeting extinction; R-S flip-flop; software algorithm 一清除键盘机械抖动方法的基本原理 按键消抖:通常的按键所用开关为机械弹性开关,当机械触点断开、闭合时,电压信号小型如下图。由于机械触点的弹性作用,一个按键开关在闭合时不会马上稳定地接通,在断开时也不会一下子断开。因而在闭合及断开的瞬间均伴随有一连串的抖动,如下图。抖动时间的长短由按键的机械特性决定,一般为5ms10ms。 按键稳定闭合时间的长短则是由操作人员的按键动作决定的,一般为零点几秒至数秒。键抖动会引起一次按键被误读多次。为确保CPU对键的一次闭合仅作一次处理,必须去除键抖动。在键闭合稳定时读取键的状态,并且必须判别到键释放稳定后再作处理。按键的抖动,可用硬件或软件两种方法。 软件方法:运用运算方法,通过运算逻辑表达式:Keradyn=Ktemp Kinput+Kreadyn-1 (Ktemp Kinput) (1)Ktemp=Kinput (2)可以获得消除抖动的按键消息。 设置3个变量Kready、Ktemp和Kinput,并设置定时中断周期为20ms。在定时中断服务程序中读取按键,并把读取的数据存于变量Kinput中。变量Kready中是所需要的稳定的按键信息;Ktemp是中间变量,它的值是上一次的Kinput。 根据当前按键的状态,考虑到Kready中是20ms抖动后的有效键信息,则Kready、Ktemp和Kinput之间,在不同时刻的状态关系如表1所列。表1时 刻KreadyKtempKinput1000200130104001511161117110810191101000011000 时刻1为没有键按下的初始状态;时刻2的Kinput为1,但时刻3的Kinput又变为0,说明时刻2的Kinput为1并不是有键按下,可能只是干扰,所以Kreqdy为0;时刻4同时刻2的情况类似,但是时刻4和时刻5时Kinput都为1,说明有按键按下,在时刻5时Kready为1;虽然时刻7时Kinput为0,但时刻5、6、8时Kinput都为1,说明按键一直按下,只不过有干扰,Kready保持为1;时刻9、10连续两个时刻Kinput为0,表示按键抬起,时刻10时Kready为0。 通过分析可以看出,Kready中是消除了抖动并在一定程度上排除了干扰的有效按键信息。从按键按下到Kready为1,最长时间约为40ms,最短约为20ms。其时间长短取决于键按下时处于定时中断周期的所在时刻。如果按键一直按下,则有效键信息以20ms的间隔重复输出。仔细分析表1,还可知道当前时刻Kready的值不但与Ktemp和Kinput有关,还与Kready前一时刻的值有关。我们把Keady的当前时刻记作Kreadyn,作为因变量;前一时刻记作Kreadyn-1,并和Ktemp、Kinput一起作为自变量,依照表1绘出卡诺图如图1所示。表达式(1)就是由图1的卡诺图得出的最简逻辑表达式。 硬件方法:在键数较少时可用硬件方法去除键抖动,下图所示的RS触发器为硬件去抖图中两个“与非”门构成一个RS触发器。当按键未按下时,输出为1;当键按下时,输出为0。此时即使用按键的机械性能,使按键因弹性抖动而产生瞬时断开(抖动跳开B),中要按键不返回原始状态A,双稳态电路的状态不改变,输出保持为0,不会产生抖动的波形。也就是说,即使B点的电压波形是抖动的,但经双稳态电路之后,其输出为正规的矩形波。这一点通过分析RS触发器的工作过程很容易得到验证。 利用电容的放电延时,采用并联电容法,也可以实现硬件消抖2 消除键盘机械抖动方法实际应用情况软件应用情况:如用C51单片机编程语言编制的8个按键的键处理程序 #include#includeunsigned char key_value;unsigned char Kinput;unsigned char Ktemp;unsigned char Kstore;unsigned char Kready;unsigned char Koutput;unsigned char bdata flag;code unsigned char Kconst=0xaa; /*重复键和非重复键格式*/sbit endebounce=flag0;sbit getkey=iag1;sbit kprocess=flag2;sbit ACC_7=ACC7;void main(void);void debounce(void);void get_key_value(void);void main(void)/*初始化*/kinput=Ktemp=kready=Kstore=0;endebounce=0;getkey=0;kprocess=0;TMOD=0x01;TL0=0xe0;TH0=0xb1;TR0=1;ET0=1;EA=1;/*/while(1)/*循环*/debounce();/*调用去除键抖动函数*/get_key_value();/*调用获取键值函数*/key_processing();/*调用键处理函数*/*other functions*/void debounce(void)if (endebounce)/*以下是去除键抖动表达式*/Kreqdy=Ktemp & Kinput |Kready & (KtempKinput);Ktemp=Kinput;/*以下表示式用于输出重复键和非重复键*/Koutput=Kready &(Kstore | Kconst);Kstore=Kready;if (Koutput ! =0)/*如果有键按下,置标志准备获取键值*/getkey=1;void get_key_value(void)待添加的隐藏文字内容2if(getkey)unsigned char temp;unsigned char j;getkey=0;/*清标志*/for(j=0;j8;j+)temp=_cror_(koutput,1);/*循环右移寻找按下的键*/if(_testbit_(ACC_7)/*如果ACC_7=1,找到了按下的键*/key_value=j;/*获得键值*/j=8;/*找到按下的键就退出循环*/kprocess=1;/*置标志,准备进行键处理*/else Koutput=temp;/*准备下一次寻找*/void timer0_interrupt_handler(void) interrupt using1TL0=0xe0;/*加载定时器参数,使晶振频率12MHz时中断周期为20ms*/TH0=0xb1;/*键扫描*/P2_0;/*使能键扫描位*/Kinput=P0;/*从P0读入按键信息,反相后保存*/endebounce;/*置标志位准备去抖动*/*其它与定时器有关的语句*/硬件应用情况:对于硬件资源丰富的FPGA系统,可以使用硬件来减轻软件工作量,通常称之为硬件加速。在按键信号输入到软件系统前用逻辑对其进行一下简单的处理即可实现所谓的硬件消抖,verilog代码如下:/对输入信号inpio硬件滤波,每20ms采样一次当前值reg18:0 cnt; /20ms计数器always (posedge clk_25m or negedge rst_n)if(!rst_n) cnt = 19d0;else if(cnt 19d500000) cnt = cnt+1b1;else cnt = 19d0;reg1:0 inpior; /当前inpio信号锁存,每20ms锁存一拍always (posedge clk_25m or negedge rst_n)if(!rst_n) inpior = 2b11;else if(cnt = 19h7ffff) inpior = inpior0,inpior;wire inpio_swin =inpior0 | inpior1; /前后20ms两次锁存值都为0时才为0该程序中设置了一个20ms计数器,通过间隔20ms对输入信号inpio采样两次,两次相同则认为键盘输入稳定,得到用硬件逻辑处理后的inpio_swin信号则是消抖处理过的信号。软件程序就不再需要delay()来滤波了,也不会出现使用纯软件处理出现的中断失去响应的情况了,这就是硬件加速的效果.3 两种方法的对比总结 消除按键抖动,永远不可能完全消除抖动,只是能消除绝大部分抖动情况。一般在键较少时可用硬件方法,作去抖动的电路,可以接电容,然后设计好充放时间常数,不能太大,要不按键不够灵敏;如果键较多,常用软件的方法,检测出键闭合后执行一个延时程序,产生几毫秒的延时,再检测键的闭合状态,确认键是否真的被按下,当检测到按键释放后,也要给出几毫秒的延时,后沿抖动消失后才能转入该键的处理程序。 在单片机应用系统中,对按键的要求是千差万别的,可根据不同的需要来选择不同地去抖动的方法。谢辞岁月如梭,如歌。转眼间,三年的求学生活即将结束,站在毕业的门槛上,回首往昔,奋斗和辛劳成为丝丝的记忆,甜美与欢笑也都尘埃落定。山东传媒职业学院以其优良的学习风气、严谨的科研氛围教我求学,以其博大包容的情怀胸襟、浪漫充实的校园生活育我成人。值此毕业论文完成之际,我谨向所有关心、爱护、帮助我的人们表示最诚挚的感谢与最美好的祝愿。 本论文是在罗东华老师的悉心指导之下完成的。三年来,导师渊博的专业知识,严谨的治学态度,精益求精的工作作风,诲人不倦的高尚师德,朴实无华、平易近人的人格魅力对我影响深远。导师不仅授我以文,而且教我做人,虽历时三载,却赋予我终生受益无穷之道。本论文从选题到完成,几易其稿,每一步都是在导师的指导下完成的,倾注了导师大量的心血,在此我向我的罗东华表示深切的谢意与祝福! 还要感谢父母在我求学生涯中给与我无微不至的关怀和照顾,一如既往地支持我、鼓励我。同时,还要感谢本班同学三年来对我的爱护、包容和帮助,愿友谊长存! 求学生涯暂告段落,但求知的道路却永无停滞。三年的大学生活给予我许多珍贵的财富,教会我许多难能的品质。精勤求学,敦笃励志,果毅力行,忠恕任事这十六字箴言将伴随我在以后的人生道路上,勇敢地不断前行。参考文献 以上资料均来自网络,道客巴巴在线文档分享平台和中国知识网等技术交流网站。Employment 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 it.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 enough to stop him completely.If he goes too fast or spins out of control, he has a stabilization parachute that can be deployed to slow him down. His team hopes its not needed. Instead, he plans to deploy his 270-square-foot (25-square-meter) main chute at an altitude of around 5,000 feet (1,524 meters).In order to deploy this chute successfully, he will have to slow to 172 mph (277 kph). He will have a reserve parachute that will open automatically if he loses consciousness at mach speeds.Even if everything goes as planned, it wont. Baumgartner still will free fall at a speed that would cause you and me to pass out, and no parachute is guaranteed to work higher than 25,000 feet (7,620 meters).cause there
展开阅读全文