资源描述:
《单片机实验二软件设计》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、实验二、单片机软件实验一、实验目的:1、进一步掌握仿真器及软件的使用;2、进一步熟悉51单片机指令系统;3、掌握汇编语言程序的设计方法;4、进一步掌握程序的调试、诊断和排错方法。二、实验仪器:1、PC机一台。2、仿真器(EASYPROBE)一只。3、稳压电源一台。YesYes开始0→R4R50→Cy16→R0移出位Cy=1?No(R4R5)+(R2R3)→R4R5(R0)-1→R0(R0)=0?ENDNoCyR4R5R6R7右移(循环)一位CyR4R5R6R7右移(循环)一位→R4R5R6R7三、实验原理:双字节无符号数
2、相乘移位加算法四、实验内容:(一)程序的运行与验证:1、把长度为10H的字符串从内部RAM的输入缓冲区inbuf向输出缓冲区outbuf进行传送,遇到0D0H或整个字符串传送完毕。设inbuf=30H,outbuf=50H(1)(30H)~(35H)=00H~05H,(36H)=0D0H,(37H)~(3FH)=07H~0FH,运行程序检查(50H)到(5FH)的内容。(2)(30H)~(3FH)=00H~0FH,运行程序检查(50H)到(5FH)的内容。INBUFEQU30HOUTBUFEQU50HORG0000HLJ
3、MPMAINORG1000H10007830MAIN:MOVR0,#INBUF10027950MOVR1,#OUTBUF10047A10MOVR2,#10H1006E6LOOP:MOVA,@R01007C3CLRC100894D0SUBBA,#0D0H100A6006JZOVER100CE6MOVA,@R0100DF7MOV@R1,A100E09INCR1100F08INCR01010DAF4DJNZR2,LOOP101280FEOVER:SJMPOVEREND2、求8个数的平均值,这8个数以表格形式存放在从table开
4、始的单元中。(1)table:db02H,03H,04H,10H,12H,22H,25H,30H运行程序检查结果。(2)table:db0C2H,0D0H,88H,92H,55H,66H,0A5H,74H修改并运行程序,检查结果。ORG0000HLJMPMAINORG1000H1000901020MAIN:MOVDPTR,#TABLE10037908MOVR1,#08H100589F0MOVB,R110077800MOVR0,#00H1009E4LOOP:CLRA100A93MOVCA,@A+DPTR100B28ADDA
5、,R0100CF8MOVR0,A100DA3INCDPTR100ED9F9DJNZR1,LOOP101084DIVAB101180FESJMP$ORG1020H10200203041012222530TABLE:DB2H,03H,04H,10H,12H,22H,25H,30HENDORG1000HMOVDPTR,#TABLEMOVR1,#08HMOVB,R1MOVR0,#00HMOVR2,#0LOOP:CLRAMOVCA,@A+DPTRADDA,R0JNCJ1INCR2J1:MOVR0,AINCDPTRDJNZR1,LO
6、OPDIVABMOVR0,AMOVA,R2MOVB,#32MULABADDA,R0SJMP$ORG1020HTABLE:DB0C2H,0D0H,88H,92HDB55H,66H,0A5H,74HEND(三)编写16位无符号数相乘的移位加算法程序:实现(R2R3)×(R6R7)→R4R5R6R7;(1)若(R2R3)=1088H,(R6R7)=20A0H,运行程序检查结果;(2)若(R2R3)=0C0FFH,(R6R7)=B080H,运行程序检查结果;(3)若(R2R3)=0050H,(R6R7)=0080H,运行程序检查
7、结果。ORG0000HACALLDBMUL1STOP:SJMPSTOPORG0100HDBMUL1:CLRA;初始化MOVR4,A;MOVR5,A;MOVR0,#16;CLRC;LOOP:MOVA,R4;R4R5R6R7右移一位RRCA;MOVR4,A;MOVA,R5;RRCA;MOVR5,A;MOVA,R6;RRCA;MOVR6,A;MOVA,R7;RRCA;MOVR7,A;JNCSKP;移出位=0,跳过双字节无符号数相乘移位加算法程序MOVA,R5;移出位0,(R4R5)+(R2R3)→R4R5ADDA,R3MOVR
8、5,A;MOVA,R4;ADDCA,R2;MOVR4,A;SKP:DJNZR0,LOOP;计数结束否MOVA,R4;R4R5R6R7右移一位RRCA;MOVR4,A;MOVA,R5;RRCA;MOVR5,A;MOVA,R6;RRCA;MOVR6,A;MOVA,R7;RRCA;MOVR7,A;RET;返回END双字节无