单片机作业参考(北航出版社)

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

第三章5、特殊寄存器:直接寻址方式。片外数据寄存器:寄存器间接寻址方式。8、MOVA,data:直接寻址MOVA,#data:立即数寻址MOVdata1,data2:直接寻址MOV74H,#78H:立即数寻址9、MOVA,@R0:(A)=80HMOV@R0,40H:(32H)=08HMOV40H,A:(40H)=80HMOVR0,#35H:(R0)=35H16、ANLA,#17H:10000011:00010111:00000011(A)=03HORL17H,A:00110100:00000011:00110111(17H)=37HXRLA,@R0:00000011:00110111:00110100(A)=34HCPLA:(A)=0CBH18、(1)MOV20H,R0MOV21H,R1MOV22H,R2MOV23H,R3MOV24H,R4MOV25H,R5MOV26H,R6MOV27H,R7(2)默认寄存器0组SETBRS0MOVR0,#00HMOVR1,#20HMOVR6,#08HLOOP:MOVA,@R0MOV@R1,AINCR0INCR1DJNZR6,LOOP.....20、MOVR3,#6FHMOVR2,#5DHMOVR1,#13HMOVR0,#0B4HCLRCMOVA,R2SUBBA,R0MOV30H,AMOVA,R3SUBBA,R1MOV31H,A21、(1)A≥10MOVR0,#0AHCLRCSUBBA,R0JZLABLEJNCLABLE.....LJMPNEXTLABLE:.....NEXT:...(2)A>10MOVRO,#0AHCLRCSUBBA,R0JNZLOOPLJMPNEXTLOOP:JNCLABLE....LJMPNEXTLABLE:....NEXT:.....(2)A≤10MOVR0,#0AHCLRCSUBBA,R0JZLABLE;=10?JCLABLE;10?.....LJMPNEXTLABLE:.....NEXT:...22、(SP)=23H,(PC)=3412H25、MOVR6,#30HMOVR0,#20HMOVR2,#0AAHNEXT:MOVA,@R0SUBBA,R2JZLOOPINCRODJNZR6,NEXTMOV51H,#00HSJMPDOWNLOOP:MOV51H,#01H....DOWN:...26、MOVR6,#31HMOVR0,#20HMOVR2,#00H;NEXT:MOVA,@R0JNZLOOPINCR2;LOOP:INCR0DJNZR6,NEXTMOV51H,R230、MOVR0,#30HMOVR1,#40HMOVR7,#04H;CLRCLOOP:MOVA,@R0ADDCA,@R1;DAAMOV@R0,A;保存和INCROINCR1DJNZR7,LOOP....31、MOVDPTR,#2000HMOVR0,#30HMOVR7,#8;NEXT:MOVXA,@DPTRMOV@R0,AINCDPTR;INCR0DJNZR7,NEXTRET33、(1)将内存单元50H--59H赋值:0(2)7A0AMOVR2,#0AH7850MOVR0,#50HE4CLRA;-5E6LOOP:MOV@R0,A;-408INCR0;-3DAFCDJNZR2,LOOP;-1,-2DONE:;当前PC位置;+1FE-|地址差|=FE-2=FC(-4)反码:11111011(-4)补码:11111100:FC(3)MOVR2,#0AHMOVR0,#50HCLRALOOP:MOV@R0,AINCR0INCADJNZR2,LOOPDONE:35、1000H53H1001H54H1002H41H1003H52H1004H54H1005H12H34H1007H30H00H1009H70H36、(2)MOVRO,#40H;MOVA,@R0;(40H)送AINCRO;指向41H单元ADDA,@R0;(40H)+(41H),结果送AINCRO;指向42H单元MOV@R0,A;结果送42H单元CLRA;ADDCA,#0;INCRO;指向43H单元MOV@RO,A;和可能的进位送43H单元。(1)40H、41H两个单元的内容相加,结果放在43H、42H单元中第五章练习2、ORG0000HLJMPMAINORG0003HLJMPINTEX0ORG000BHLJMPINTET0ORG0013HLJMPINTEX1ORG0023HLJMPINTESORG0030HMAIN:.....SETBPT0MOVIE,#97H;10010111;SETBEX0;SETBEX1;SETBET0;SETBES;SETBEA......HERE:SJMPHEREORG1000HINYEX0:.....RETIORG1200HINTET0:......RETIORG1400HINTEX1:......RETIORG1600HINTES:......RETIEND14、设振荡频率12MHz,则机器周期:1us定时方式:T0,方式1。最大定时时间:216=65536us=65.536ms用此定时50ms,乘以20得1s,再乘60得1min计算T0初值:(216-X)*1us=50*1000usX=15536=3CB0HTL0=0B0HTH0=3CHORG0000HLJMPMAINORG000BHLJMPINTT0ORG0030HMAIN:MOVSP,#60HMOVTMOD,#01H;00000001;T0模式1,定时MOVR6,#20;秒MOVR7,#60;分MOVTL0,#0B0HMOVTH0,#3CHSETBEASETBET0SETBTR0;启动T0LOOPS:CJNER6,#00H,LOOPSSETBP1.0;秒脉冲输出CLRP1.0MOVR6,#20DECR7CJNER7,#00H,LOOPSSETBP1.1;分脉冲输出CLRP1.1MOVR7,#60SJMPLOOPSINTT0:MOVTLO,#0B0HMOVTH0,#3CHDECR6RETI第六章练习2、用P1.0输出用T0定时,方式2机器周期:1us100kHz的周期为:0.01ms=10us则定时5us计算T0初值:(28-X)*1us=5usX=251=FBHORG0000HLJMPMAINORG000BHCPLP1.0RETIORG0030HMAIN:MOVSP,#60HMOVTMOD,#02H;00000010;T0模式2,定时MOVTL0,#0FBHMOVTH0,#0FBHSETBEASETBET0SETBTR0;启动T0HERE:SJMPHERE8、T1方式1,计数时的初值:216-X=1000X=64536=FC18H定时时的初值:(216-Y)*2us=10*1000usY=60536=EC78HORG0000HLJMPMAINORG0030HMAIN:CLRTR1MOVTMOD,#50H;01010000;T1模式1,计数MOVTL1,#18HMOVTH1,#0FCHSETBTR1;启动T1LOOPC:JBCTF1,STIME;T1溢出表示1000个计数脉冲到SJMPLOOPCSTIME:CLRTR1;停止计数MOVTMOD,#10H;00010000T1模式1,定时MOVTL1,#78HMOVTH1,#0ECHSETBTR1LOOPT:JBCTF1,SCONT;T1溢出表示定时时间到SJMPLOOPTSCONT:LJMPMAIN13、T0方式1,定时、查寻方式高电平初值:(216-XH)*2us=50usXH=FFE7H低电平初值:(216-XL)*2us=300usXH=FF6AHORG0000HLJMPMAINORG0030HMAIN:MOVTMOD,#01H;00000001;T0模式1,定时SETBTR0;启动T0NEXT:MOVTL1,#0E7HMOVTH1,#0FFHLOOP:JBCTF0,SETH;高电平定时到SJMPLOOPSETH:CLRP1.0MOVTL1,#6AHMOVTH1,#0FFHLOOP1:JBCTF0,SETL;低电平定时到SJMPLOOP1SETL:SETBP1.0AJMPNEXT14、f=12MHzT1定时250uS如模式1:FF06H如模式2:06HORG0000HLJMPMAINORG0030HMAIN:MOVR2,#04HCLRP1.0CLRP1.1MOVTMOD,#20H;00100000,T1模式2,MOVTL1,#06HMOVTH1,#06HSETBTR1;启动T1LOOP:JBCTF1,L1;SJMPLOOPL1:CPLP1.1DJNZR2,LOOPCPLP1.0MOVR2,#04HLJMPLOOPRET18、T0方式2:200us定时的初值:(28-X)*1us=200usX=56=38H周期为2ms的方波定时1ms产生方法:200us*5=1000usORG0000HLJMPMAINORG0030HMAIN:MOVR6,#05HMOVTMOD,#01H;00000010;T0模式2,定时NEXT:MOVTL0,#38HMOVTH0,#38HSETBTR0;启动T0LOOP:JBCTF0,SETIME;定时200us到SJMPLOOPSETIME:DECR6CJNER6,#00H,LOOPCPLP1.0MOVR6,#05HSJMPLOOP19、f=12MHzT0定时50mS,50mS*20=1S,1s*60=1Min如模式1:3CB0HORG0000HLJMPMAINORG000BHLJMPT0INTORG0030HMAIN:MOVR0,#00HMOVR1,#00HMOVTMOD,#01HMOVTL0,#0B0HMOVTH0,#3CHSETBEASETBET0SETBTR0;启动T1CLRCLOOP:LJMPLOOP;中断子程ORG0200HTOINT:MOVTMOD,#01HMOVTL0,#0B0HINCR0MOVA,#20SUBBA,R0JNZL1CLRP1.0SETBP1.0CLRP1.0MOVR0,#0INCR1MOVA,#60SUBBA,R1JNZL1CLRP1.1SETBP1.1CLRP1.1MOVR1,#0L1:RETI第七章7、SCON:01010000波特率:T1模式2,初值:E8HORG0000HLJMPMIANORG0030HMAIN:MOVSP,#60HMOVTMOD,#00100000BMOVTL0,#0E8HMOVTH0,#0E8HSETBTR1MOVSCON,#01010000BHERE:JNBRI,HERECLRRIMOVA,SBUFNOPMOVSBUF,AJNBTI,$CLRTIEND13SCON:01010000波特率:T1模式2,初值:E8HORG0000HLJMPMIANORG0023HLJMPSP_INTORG0030HMAIN:MOVSP,#60HMOVR0,#ADDR_RX;发送首址MOVR1,#ADDR_TX;接收首址MOVSCON,#01010000BMOVTMOD,#00100000BMOVTL0,#0E8HMOVTH0,#0E8HSETBTR1SETBESSETBEAACALLSP_OUT;发送子程HERE:SJMPHERESP_INT:JBTI,SEND;发送、接收判断ACALLSP_INSJMPNEXTSEND:ACALLSP_OUTNEXT:RETISP_OUT:CLRTIMOVA,@R0MOVSBUF,AINCR0RETSP_IN:CLRRI;接收子程MOVA,SBUFMOV@R1,AINCR1RET17、单片机的频率串行通信方式参见:p176乙机接收正确回发:00H乙机接收不正确回发:FFH甲机发送:SCON:11010000波特率:T1模式2,初值:E8HORG0000HLJMPMIANORG0023HLJMPSP_INTORG0030HMAIN:MOVSP,#60HMOVR0,#30H;发送首址MOVR7,#0FH;发送字节数M

1 / 20
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功