资源描述:
《单片机程序说课材料.doc》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、单片机程序__________________________________________________1、编程将片内RAM30H单元开始的15B的数据传送到片外RAM3000H开始的单元中去。解:STRAT:MOVR0,#30HMOVR7,#0FHMOVDPTR,#3000HLOOP:MOVA,@R0MOVX@DPTR,AINCR0INCDPTRDJNZR7,LOOPRET2、编程将片内RAM40H单元中的内容送到片外RAM2000H单元中。解:ORG0100HMOVA,40HMOVDPTR,#2000HMOVX@DPTR,AEND___________________________
2、_________________________________________________________________________3、将内部RAM40H开始的10个字节的数搬到外部RAM2000H处MOVDPTR,#2000HMOVR0,#40HMOVR2,#0AHLOOP:MOVA,@R0MOVX@DPTR,AINCR0INCDPTRDJNZR2,LOOPSJMP$END4、将存于外部RAM8000H开始的50H数据传送0010H的区域,请编程实现。MOVDPTR,#8000HMOVR0,#10HMOVR2,#50HLOOP:MOVXA,@DPTR;取数MOVX@R0,A;存
3、数1NCDPTR1NCR0DJNZR2,LOOPRET________________________________________________________________________________________________________________________________________________________________________________________________________5.片内RAM40H开始的单元内有10B二进制数,编程找出其中最大值并存于50H单元中.解START:MOVR0,#40H;数据块首地址送R0MO
4、VR7,#09H;比较次数送R7 MOVA,@R0;取数送ALOOP:INCR0MOV30H,@R0;取数送30HCJNEA,30H,NEHT;(A)与(30H)相比NEXT:JNCBIE1(A)≥(30H)转BIR1MOVA,30H;(A)<(30H),大数送A BIE1:DJNZR7,LOOP;比较次数减1,不为0,继续比较 MOV50H,A;比较结束,大数送50H RET6.片内RAM30H开始的单元中有10B的二进制数,请编程求它们之和(和<256).___________________________________________________________
5、_________________________________________解 ADDIO:MOVR0,30HMOVR7,#9MOVA,@R0LOOP:INCR0ADDA,@R0DJNZR7,LOOPMOV30H,ARET____________________________________________________________________________________________________7、设从内存BLOCK单元开始存放一无符号数的数据块,其长度为LEN。试找出其最小数,并存入MIN单元。COMP:MOVA,#0FFH;置比较的初始值MOVR2,#LEN;
6、置数据块长度____________________________________________________________________________________________________MOVR1,#BLOCK;置地址指针LOOP:CLRCSUBBA,@R1;比较JCNEXT;若小,则恢复原值MOVA,@R1SJMPNEXT1NEXT:ADDA,@R1NEXT1:INCR1;若大,则取下个数比较DJNZ:DJNZR2,LOOPMOVMN,A;存最小数SJMP$8、比较存放在ONE,TWO,TRE三个单元的无符号数,并将小数存放在20H单元中。MOVA,ONECJNEA
7、,TWO,RRRR:JCSSMOVA,TWOCJNEA,TRE,TTTT:JCWWSJMPUUSS:CJNEA,TRE,VVVV:JCWWUU:MOVA,TREWW:MOV20H,A____________________________________________________________________________________________________9、设在单片机内部