复合硅酸盐厂家
免费服务热线

Free service

hotline

010-00000000
复合硅酸盐厂家
热门搜索:
行业资讯
当前位置:首页 > 行业资讯

按键与数码管汇编例程

发布时间:2020-07-21 19:28:16 阅读: 来源:复合硅酸盐厂家

/*程序效果:八个数码管同时显示,按键最后按下的八个数值*/ ORG 0000H LJMP START ORG 0030HSTART: MOV 30H,#00 //赋初值 MOV 31H,#00 MOV 32H,#00 MOV 33H,#00 MOV 34H,#00 MOV 35H,#00 MOV 36H,#00 MOV 37H,#00 MOV P1,#0FFH //打开最右边的数码管 MOV P2,#00 //给P2口送0值LOOP: LCALL KEY //不断扫描键盘 LCALL DISPLAY //不断显示值 LJMP LOOP//键盘扫描子程序KEY: MOV R0,#0FEH //赋初值,用于循环,不断扫描键值 MOV R2,#04 //总循环4次LRP: MOV A,R0 //暂存A的值 MOV P0,A RL A //循环左移1位 XCH A,R0 MOV A,P0 //读?P0口的值 CJNE A,#7EH,LKP //判断按键0是否按下 MOV 40H,#3FH //是,则将键值暂存在40h单元中LFP: MOV A,P0 //读?P0口的值 CJNE A,#7EH, LKOP1 //判断按键是否松手 LCALL DISPLAY //按键没有松手,继续显示 LJMP LFP //等待按键松手,否则继续循环LKP: CJNE A,#0BEH,LKP1 //以下功能同上 MOV 40H,#66H LFP1: MOV A,P0 CJNE A,#0BEH,LKOP1 LCALL DISPLAY LJMP LFP1LKP1: CJNE A,#0DEH,LKP2 MOV 40H,#7FHLFP2: MOV A,P0 CJNE A,#0DEH,LKOP1 LCALL DISPLAY LJMP LFP2LKP2: CJNE A,#0EEH,LKP3 MOV 40H,#39HLFP3: MOV A,P0 CJNE A,#0EEH,LKOP1 LCALL DISPLAY LJMP LFP3

LKP3: CJNE A,#7DH,LKP4 MOV 40H,#06HLFP4: MOV A,P0 CJNE A,#7DH,LKOP1 LCALL DISPLAY LJMP LFP4LKP4: CJNE A,#0BDH,LKP5 MOV 40H,#06DHLFP5: MOV A,P0 CJNE A,#0BDH,LKOP1 LCALL DISPLAY LJMP LFP5LKP5: CJNE A,#0DDH,LKP6 MOV 40H,#6FHLFP6: MOV A,P0 CJNE A,#0DDH,LKOP1 LCALL DISPLAY LJMP LFP6 LKOP1: LJMP LKOP //加本条语句的作用是:扩大CJNE的跳转范围

LKP6: CJNE A,#0EDH,LKP7 MOV 40H,#5EHLFP7: MOV A,P0 CJNE A,#0EDH,LKOP1 LCALL DISPLAY LJMP LFP7

LKP7: CJNE A,#7BH,LKP8 MOV 40H,#5BHLFP8: MOV A,P0 CJNE A,#7BH,LKOP1 LCALL DISPLAY LJMP LFP8LKP8: CJNE A,#0BBH,LKP9 MOV 40H,#7DHLFP9: MOV A,P0 CJNE A,#0BBH,LKOP LCALL DISPLAY LJMP LFP9LKP9: CJNE A,#0DBH,LKP10 MOV 40H,#77HLFP10: MOV A,P0 CJNE A,#0DBH,LKOP LCALL DISPLAY LJMP LFP10LKP10: CJNE A,#0EBH,LKP11 MOV 40H,#79HLFP11: MOV A,P0 CJNE A,#0EBH,LKOP LCALL DISPLAY LJMP LFP11

LKP11: CJNE A,#77H,LKP12 MOV 40H,#4FHLFP12: MOV A,P0 CJNE A,#77H,LKOP LCALL DISPLAY LJMP LFP12LKP12: CJNE A,#0B7H,LKP13 MOV 40H,#07HLFP13: MOV A,P0 CJNE A,#0B7H,LKOP LCALL DISPLAY LJMP LFP13LKP13: CJNE A,#0D7H,LKP14 MOV 40H,#7CHLFP14: MOV A,P0 CJNE A,#0D7H,LKOP LCALL DISPLAY LJMP LFP14LKP14: CJNE A,#0E7H,LKP15 MOV 40H,#71HLFP15: MOV A,P0 CJNE A,#0E7H,LKOP LCALL DISPLAY LJMP LFP15LKOP: MOV 37H,36H //以下语句的作用是:在有按键按下时 MOV 36H,35H //所有数据左移一位,空出30H单元 MOV 35H,34H MOV 34H,33H MOV 33H,32H MOV 32H,31H MOV 31H,30H MOV 30H,40HLKP15: DJNZ R2,LRP1 //以下三条语句的作用是:扩大DJNZ的跳转范围 LJMP LRP2LRP1: LJMP LRPLRP2: NOP RET//显示子程序DISPLAY: MOV R1,#0FFH MOV P1,R1 //点亮最右边的数码管 MOV P2,30H //显示30H单元的内容 LCALL DELAY //延时,使数码管更加亮,但时间要适宜 DEC R1 //准备点亮下一个数码管

MOV P1,R1 //点亮下一个数码管 MOV P2,31H LCALL DELAY DEC R1

MOV P1,R1 MOV P2,32H LCALL DELAY DEC R1

MOV P1,R1 MOV P2,33H LCALL DELAY DEC R1

MOV P1,R1 MOV P2,34H LCALL DELAY DEC R1

MOV P1,R1 MOV P2,35H LCALL DELAY DEC R1

MOV P1,R1 MOV P2,36H LCALL DELAY DEC R1

MOV P1,R1 MOV P2,37H LCALL DELAY RET//延时时间约为:2us*250=15msDELAY: MOV R6,#250DEL1: DJNZ R6,DEL1 RET END

杭州吸脂价格

长沙吸脂

重庆双眼皮修复