您好,欢迎访问三七文档
当前位置:首页 > 电子/通信 > 综合/其它 > 单片机简易计算器设计(汇编语言)
KEYBUFEQU40H;键号存放单元ORG0000HLJMPMAINORG0030HMAIN:MOVKEYBUF,#0;初始键号设位0,也可以为任意值MOVR0,#30H;显示首地址MOVR2,#0CH;计算数据存放单元个数CLRAQING:MOV@R0,A;将数据存放单元清零INCR0DJNZR2,QINGMOVP0,#8FH;关闭显示MOVR1,#30H;将显示首地址存放R1里;===============================================;五位无符号显示子程序DIS1:MOVR0,#30H;把显示数据第一位放在R0里MOVR2,#04H;把显示的位码放在R2里MOVR3,#05H;把显示的长度放在R3里DIS2:MOVA,@R0ANLA,#0FH;屏蔽显示数据的高四位MOVB,AMOVA,R2ANLA,#0FH;屏蔽位码的高四位SWAPAORLA,BMOVP0,A;送总显示数据到P0显示LCALLDELY4ms;调用延时4msINCR0;取下一个显示数据DECR2DJNZR3,DIS2;四位显示晚后重新开始显示;===================================================;键盘扫描子程序WAIT:MOVP1,#0FFH;P1口送高电平CLRP1.0;第一行清零MOVA,P1;读P1口ANLA,#0F0H;低位屏蔽XRLA,#0F0H;判断低位是否有低电平,即判断是否有按键按下JZNOKEY1;地位有低电平继续扫描,否者跳到第而行去扫描LCALLDELY10ms;延时10ms去抖在进行判断是否有按键按下MOVA,P1;继续读P1口ANLA,#0F0H;判断低位是否有低电平CJNEA,#0E0H,NK1;如果扫描数据不为0E0H就转到NK1MOVKEYBUF,#0;否者判断为0号键AJMPDK;转DK1查表程序NK1:CJNEA,#0D0H,NK2;如果扫描数据不为0D0H就转到NK2MOVKEYBUF,#1;否者判断为1号键AJMPDK;转DK2查表程序NK2:CJNEA,#0B0H,NK3;如果扫描数据不为0B0H就转到NK3MOVKEYBUF,#2;否者判断为2号键AJMPDK;转DK3查表程序NK3:CJNEA,#70H,NK4;如果扫描数据不为70H就转到NK4LJMPSAN_CHUNK4:NOPNOKEY1:MOVP1,#0FFH;和上面相同CLRP1.1MOVA,P1ANLA,#0F0HXRLA,#0F0HJZNOKEY2LCALLDELY10MSMOVA,p1ANLA,#0F0HXRLA,#0F0HJZNOKEY2MOVA,P1ANLA,#0F0HCJNEA,#0E0H,NK5MOVKEYBUF,#3AJMPDKNK5:CJNEA,#0D0H,NK6MOVKEYBUF,#4AJMPDKNK6:CJNEA,#0B0H,NK7MOVKEYBUF,#5AJMPDKNK7:CJNEA,#70H,NK8MOVKEYBUF,#10;否者判断为3号键AJMPDK;转DK4查表程序NK8:NOPNOKEY2:MOVP1,#0FFHCLRP1.2MOVA,P1ANLA,#0F0HXRLA,#0F0HJZNOKEY3LCALLDELY10MSMOVA,P1ANLA,#0F0HXRLA,#0F0HJZNOKEY3MOVA,P1ANLA,#0F0HCJNEA,#0E0H,NK9MOVKEYBUF,#6AJMPDKNK9:CJNEA,#0D0H,NK10MOVKEYBUF,#7AJMPDKNK10:CJNEA,#0B0H,NK11MOVKEYBUF,#8AJMPDKNK11:CJNEA,#70H,NK12LJMPDENG_HAONK12:NOPNOKEY3:MOVP1,#0FFHCLRP1.3MOVA,P1ANLA,#0F0HXRLA,#0F0HJZNOKEY4LCALLDELY10MSMOVA,P1ANLA,#0F0HXRLA,#0F0HJZNOKEY4MOVA,P1ANLA,#0F0HCJNEA,#0E0H,NK13LJMPCHUNK13:CJNEA,#0D0H,NK14LJMPCHENGNK14:CJNEA,#0B0H,NK15LJMPJIANNK15:CJNEA,#70H,NK16LJMPJIANK16:NOP;=======================================================;查表求键值程序DK:MOVB,#00HMOVA,KEYBUF;查表程序查对应的键号数据MOVDPTR,#TABLE;把表头地址放入DPTRMOVCA,@A+DPTR;A里面存放的为键号,利用A和表头地址找到对应的键号数据MOVB,A;把查到的数据送往显示单元INCR1;取下一个显示单元MOVA,R1CJNEA,#36H,DKA1;判断显示单元是否已满MOVR1,#35H;35H,36H单元用于更好的控制五位显示AJMPDKADKA1:MOV34H,33H;按键代码按左移显示,先按先显示MOV33H,32HMOV32H,31HMOV31H,30HMOV30H,BDKA:MOVA,P1;读P1口ANLA,#0F0H;屏蔽高四位XRLA,#0F0H;地位是有低电平JNZDKA;如果有低电平继续读P1口,否者向下执行,查找第二行NOKEY4:LJMPDIS1;===================================;功能按键功能设定DENG_HAO:MOVDPTR,#JI_SUAN;等号键功能通过加、减、乘、除设定的偏移量来调用子程序MOVA,3CH;3CH存放的为功能程序入口地址偏移量JMP@A+DPTR;转移到按键功能程序JI_SUAN:AJMPJIA1;加计算子程序AJMPJIAN1;减计算子程序AJMPCHENG1;乘计算子程序AJMPCHU;除计算子程序;=======删除键功能SAN_CHU:ACALLQING_DISAJMPDKA;=======加键功能JIA:MOV3CH,#00HACALLCUN_SHUACALLQING_DISAJMPDKA;=======减键功能JIAN:MOV3CH,#02HACALLCUN_SHUACALLQING_DISAJMPDKA;=======乘键功能CHENG:MOV3CH,#04HACALLCUN_SHUACALLQING_DISAJMPDKA;=======除键功能CHU:MOV3DH,#06HACALLCUN_SHUACALLQING_DISAJMPDKA;=================================;存被加(减、乘、除)数,存放在37H~3BH里CUN_SHU:MOV37H,30H;36H存放的为最低位MOV38H,31HMOV39H,32HMOV3AH,33HMOV3BH,34H;3AH存放的为最高位RET;================================;清除显示单元QING_DIS:MOVR1,#30HQING1:MOV@R1,#00HINCR1MOVA,R1CJNEA,#36H,QING1MOVR1,#30HLOP1:RET;================================;十进制加法子程序JIA1:MOVA,37H;个位被加数ADDA,30H;个位被加数+加数MOVB,#10;十六进制除10转换成BCD码DIVABMOV30H,B;余数即个位存放在30HMOV37H,A;商存放在37HMOVA,38H;十位被加数ADDA,31H;十位被加数+加数ADDA,37H;加上个位之和的进位MOV37H,#00H;清除37HMOVB,#10;十六进制除10转换成BCD码DIVABMOV31H,B;余数即十位存放在31HMOV38H,A;商存放在38HMOVA,39H;百位计算同十位ADDA,32HADDA,38HMOV38H,#00HMOVB,#10DIVABMOV32H,BMOV39H,AMOVA,3AH;千位计算同十位ADDA,33HADDA,39HMOV39H,#00HMOVB,#10DIVABMOV33H,BMOV3AH,AMOVA,3BH;万位计算同十位ADDA,34HADDA,3AHMOV3AH,#00HMOVB,#10DIVABMOV34H,BMOV3BH,#00HAJMPDKA;=====================JIAN1:AJMPDKACHENG1:AJMPDKACHU1:AJMPDKA;=============================================;延时程序和查表表格DELY4ms:MOVR6,#8;延时4毫秒D1:MOVR7,#248DJNZR7,$DJNZR6,D1RETDELY10ms:MOVR6,#20;延时10毫秒D2:MOVR7,#248DJNZR7,$DJNZR6,D2RETTABLE:DB07H,04H,01H;/本表格是以键盘为参考789/DB08H,05H,02H;*456*DB09H,06H,03H;-123-DB00H,00H;=+清除0=+END
本文标题:单片机简易计算器设计(汇编语言)
链接地址:https://www.777doc.com/doc-2728604 .html