⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dpjjx27.htm

📁 本单片机教程是平凡老师花了大量时间
💻 HTM
📖 第 1 页 / 共 2 页
字号:
<P ALIGN="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">KEYPROC:</P>
</FONT>
<P ALIGN="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">
<FONT SIZE=2>&#9;MOV&#9;A,B&#9;&#9;;</font><FONT FACE="宋体" LANG="ZH-CN" SIZE=2>从</FONT><FONT SIZE=2>B</FONT><FONT FACE="宋体" LANG="ZH-CN" SIZE=2>寄存器中获取键值</font></P>
<P ALIGN="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">
<FONT SIZE=2>JB&#9;ACC.2,KeyStart&#9;;</FONT><FONT FACE="宋体" LANG="ZH-CN" SIZE=2>分析键的代码,某位被按下,则该位为</FONT><FONT SIZE=2>1</FONT><FONT FACE="宋体" LANG="ZH-CN" SIZE=2>(因为在键盘程序中已取反)</font></P>
<P ALIGN="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">
<FONT SIZE=2>JB&#9;ACC.3,KeyOver</font></P><FONT SIZE=2>
<P ALIGN="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">&#9;JB&#9;ACC.4,KeyUp</P>
<P ALIGN="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">&#9;JB&#9;ACC.5,KeyDown</P>
<P ALIGN="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">&#9;AJMP&#9;KEY_RET</P>
<P ALIGN="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">KeyStart:</P>
</FONT>
<P ALIGN="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">
<FONT SIZE=2>&#9;SETB&#9;StartEnd&#9;;</font><FONT FACE="宋体" LANG="ZH-CN" SIZE=2>第一个键按下后的处理</font></P>
<P ALIGN="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">
<FONT SIZE=2>AJMP&#9;KEY_RET</font></P><FONT SIZE=2>
<P ALIGN="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">KeyOver:</P>
</FONT>
<P ALIGN="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">
<FONT SIZE=2>&#9;CLR&#9;StartEnd&#9;;</font><FONT FACE="宋体" LANG="ZH-CN" SIZE=2>第二个键按下后的处理</font></P>
<P ALIGN="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">
<FONT SIZE=2>AJMP&#9;KEY_RET</font></P>
<P ALIGN="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">
<FONT SIZE=2>KeyUp:&#9;SETB&#9;UpDown&#9;&#9;;</font><FONT FACE="宋体" LANG="ZH-CN" SIZE=2>第三个键按下后的处理</font></P>
<P ALIGN="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">
<FONT SIZE=2>AJMP&#9;KEY_RET</font></P><FONT SIZE=2>
<P ALIGN="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">KeyDown:</P>
</FONT>
<P ALIGN="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">
<FONT SIZE=2>&#9;CLR&#9;UpDown&#9;&#9;;</font><FONT FACE="宋体" LANG="ZH-CN" SIZE=2>第四个键按下后的处理</font></P>
<FONT SIZE=2>
<P ALIGN="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">KEY_RET:RET</P>
<P ALIGN="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">KEY:</P>
</FONT>
<P ALIGN="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">
<FONT SIZE=2>&#9;CLR&#9;F0&#9;&#9;;</font><FONT FACE="宋体" LANG="ZH-CN" SIZE=2>清</FONT><FONT SIZE=2>F0</FONT><FONT FACE="宋体" LANG="ZH-CN" SIZE=2>,表示无键按下。</font></P>
<P ALIGN="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">
<FONT SIZE=2>ORL&#9;P3,#00111100B&#9;;</FONT><FONT FACE="宋体" LANG="ZH-CN" SIZE=2>将</FONT><FONT SIZE=2>P3</FONT><FONT FACE="宋体" LANG="ZH-CN" SIZE=2>口的接有键的四位置</FONT><FONT SIZE=2>1</font></P>
<P ALIGN="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">
<FONT SIZE=2>&#9;MOV&#9;A,P3&#9;&#9;;</font><FONT FACE="宋体" LANG="ZH-CN" SIZE=2>取</FONT><FONT SIZE=2>P3</FONT><FONT FACE="宋体" LANG="ZH-CN" SIZE=2>的值</font></P>
<P ALIGN="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">
<FONT SIZE=2>ORL&#9;A,#11000011B&#9;;</FONT><FONT FACE="宋体" LANG="ZH-CN" SIZE=2>将其余</FONT><FONT SIZE=2>4</FONT><FONT FACE="宋体" LANG="ZH-CN" SIZE=2>位置</FONT><FONT SIZE=2>1</font></P>
<P ALIGN="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">
<FONT SIZE=2>&#9;CPL&#9;A&#9;&#9;;</font><FONT FACE="宋体" LANG="ZH-CN" SIZE=2>取反</font></P>
<P ALIGN="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">
<FONT SIZE=2>JZ&#9;K_RET&#9;&#9;;</FONT><FONT FACE="宋体" LANG="ZH-CN" SIZE=2>如果为</FONT><FONT SIZE=2>0</FONT><FONT FACE="宋体" LANG="ZH-CN" SIZE=2>则一定无键按下</font></P>
<P ALIGN="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">
<FONT SIZE=2>ACALL&#9;DELAY&#9;&#9;;</FONT><FONT FACE="宋体" LANG="ZH-CN" SIZE=2>否则延时去键抖</font></P>
<P ALIGN="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">
<FONT SIZE=2>ORL&#9;P3,#00111100B</font></P><FONT SIZE=2>
<P ALIGN="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">&#9;MOV&#9;A,P3</P>
<P ALIGN="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">&#9;ORL&#9;A,#11000011B</P>
<P ALIGN="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">&#9;CPL&#9;A</P>
<P ALIGN="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">&#9;JZ&#9;K_RET</P>
</FONT>
<P ALIGN="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">
<FONT SIZE=2>&#9;MOV&#9;B,A&#9;&#9;;</font><FONT FACE="宋体" LANG="ZH-CN" SIZE=2>确实有键按下,将键值存入</FONT><FONT SIZE=2>B</FONT><FONT FACE="宋体" LANG="ZH-CN" SIZE=2>中</font></P>
<P ALIGN="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">
<FONT SIZE=2>SETB&#9;F0&#9;&#9;;</FONT><FONT FACE="宋体" LANG="ZH-CN" SIZE=2>设置有键按下的标志</font></P>
<FONT SIZE=2>
<P ALIGN="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">K_RET:&#9;&#9;&#9;&#9;</P>
</FONT>
<P ALIGN="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">
<FONT SIZE=2>&#9;ORL&#9;P3,#00111100B&#9;;</font><FONT FACE="宋体" LANG="ZH-CN" SIZE=2>此处循环等待键的释放</font></P>
<P ALIGN="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">
<FONT SIZE=2>MOV&#9;A,P3</font></P><FONT SIZE=2>
<P ALIGN="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">&#9;ORL&#9;A,#11000011B</P>
<P ALIGN="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">&#9;CPL&#9;A</P>
</FONT>
<P ALIGN="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">
<FONT SIZE=2>&#9;JZ&#9;K_RET1&#9;&#9;;</font><FONT FACE="宋体" LANG="ZH-CN" SIZE=2>直到读取的数据取反后为</FONT><FONT SIZE=2>0</FONT><FONT FACE="宋体" LANG="ZH-CN" SIZE=2>说明键释放了,才从键盘处理程序中返回</font></P>
<P ALIGN="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">
<FONT SIZE=2>AJMP&#9;K_RET</font></P><FONT SIZE=2>
<P ALIGN="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">K_RET1:&#9;</P>
<P ALIGN="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">&#9;RET</P>
<P ALIGN="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">;-----------------------------------&#9;</P>
</FONT>
<P ALIGN="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">
<FONT SIZE=2>D500MS:&#9;&#9;&#9;&#9;;</font><FONT FACE="宋体" LANG="ZH-CN" SIZE=2>流水灯的延迟时间</font></P>
<P ALIGN="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">
<FONT SIZE=2>PUSH&#9;PSW</font></P><FONT SIZE=2>
<P ALIGN="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">&#9;SETB&#9;RS0</P>
<P ALIGN="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">&#9;MOV&#9;R7,#200</P>
<P ALIGN="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">D51:&#9;MOV&#9;R6,#250</P>
<P ALIGN="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">D52:&#9;NOP</P>
<P ALIGN="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">&#9;NOP</P>
<P ALIGN="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">&#9;NOP</P>
<P ALIGN="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">&#9;NOP</P>
<P ALIGN="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">&#9;DJNZ&#9;R6,D52</P>
<P ALIGN="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">&#9;DJNZ&#9;R7,D51</P>
<P ALIGN="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">&#9;POP&#9;PSW</P>
<P ALIGN="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">&#9;RET&#9;</P>
<P ALIGN="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">;-----------------------------------</P>
<P ALIGN="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">LAMP:</P>
</FONT>
<P ALIGN="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">
<FONT SIZE=2>&#9;JB&#9;StartEnd,LampStart&#9;;</font><FONT FACE="宋体" LANG="ZH-CN" SIZE=2>如果</FONT><FONT SIZE=2>StartEnd=1</FONT><FONT FACE="宋体" LANG="ZH-CN" SIZE=2>,则启动</font></P>
<P ALIGN="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">
<FONT SIZE=2>MOV&#9;P1,#0FFH</font></P>
<P ALIGN="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">
<FONT SIZE=2>&#9;AJMP&#9;LAMPRET&#9;&#9;;</font><FONT FACE="宋体" LANG="ZH-CN" SIZE=2>否则关闭所有显示,返回</font></P>
<FONT SIZE=2>
<P ALIGN="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">LampStart:</P>
</FONT>
<P ALIGN="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">
<FONT SIZE=2>&#9;JB&#9;UpDown,LAMPUP&#9;;</font><FONT FACE="宋体" LANG="ZH-CN" SIZE=2>如果</FONT><FONT SIZE=2>UpDown=1</FONT><FONT FACE="宋体" LANG="ZH-CN" SIZE=2>,则向上流动</font></P>
<P ALIGN="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">
<FONT SIZE=2>MOV&#9;A,LAMPCODE</font></P>
<P ALIGN="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">
<FONT SIZE=2>&#9;RL&#9;A&#9;&#9;;</font><FONT FACE="宋体" LANG="ZH-CN" SIZE=2>实际就是左移位而已</font></P>
<P ALIGN="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">
<FONT SIZE=2>MOV&#9;LAMPCODE,A&#9;</font></P><FONT SIZE=2>
<P ALIGN="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">&#9;MOV&#9;P1,A</P>
<P ALIGN="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">&#9;LCALL&#9;D500MS</P>
<P ALIGN="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">&#9;AJMP&#9;LAMPRET</P>
<P ALIGN="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">LAMPUP:</P>
<P ALIGN="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">&#9;MOV&#9;A,LAMPCODE</P>
</FONT>
<P ALIGN="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">
<FONT SIZE=2>&#9;RR&#9;A&#9;&#9;;</font><FONT FACE="宋体" LANG="ZH-CN" SIZE=2>向下流动实际就是右移</font></P>
<P ALIGN="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">
<FONT SIZE=2>MOV&#9;LAMPCODE,A</font></P><FONT SIZE=2>
<P ALIGN="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">&#9;MOV&#9;P1,A</P>
<P ALIGN="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">&#9;LCALL&#9;D500MS</P>
<P ALIGN="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">LAMPRET:&#9;</P>
<P ALIGN="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">&#9;RET</P>
<P ALIGN="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">END</P>
</FONT><FONT FACE="宋体" LANG="ZH-CN" SIZE=2>
<P ALIGN="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">以上程序功能很简单,但它演示了一个键盘处理程序的基本思路,程序本身很简单,也不很实用,实际工作中还会有好多要考虑的因素,比如主循环每次都调用灯的循环程序,会造成按键反应“迟钝”,而如果一直按着键不放,则灯不会再流动,一直要到松开手为止,等等,大家可以仔细考虑一下这些问题,再想想有什么好的解决办法。</P>
</FONT>
<P ALIGN="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">
<FONT SIZE=2>2</font><FONT FACE="宋体" LANG="ZH-CN" SIZE=2>、采用中断方式:如图</FONT><FONT SIZE=2>4</FONT><FONT FACE="宋体" LANG="ZH-CN" SIZE=2>所示。各个按键都接到一个与非上,当有任何一个按键按下时,都会使与门输出为低电平,从而引起单片机的中断,它的好处是不用在主程序中不断地循环查询,如果有键按下,单片机再去做相应的处理。</font></P>
<P ALIGN="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0"> </P>
</BODY>
</HTML>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -