1.1查表程序设计(DPTR)【功能1】在片内RAM区中生成十六进制数组Hex:00H、01H、…、0EH、0FH,数组Hex的首地址为10H。【功能2】用DB伪指令在程序中定义Hex数组元素ASCⅡ码表,表首地址用符号地址TABLE表示。【功能3】用MOVCA,@A+DPTR指令编写查表程序,实现用查表方式将数组Hex的十六进制数转换为ASCⅡ码并存入片内RAM数组Asc中,数组Asc首地址70H。ORG0000HSJMPMAINORG0030HHexEQU10HAscEQU70HMAIN:MOVR0,#HexMOVR1,#AscMOVR7,#16MOVA,#00HLOOP:MOV@R0,AINCAINCR0DJNZR7,LOOPMOVR0,#HexMOVR7,#16MOVDPTR,#TABLETrans:MOVA,@R0MOVCA,@A+DPTRMOV@R1,AINCR0INCR1DJNZR7,TransTABLE:DB0123456789ABCDEFEND1.2查表程序设计(PC)【功能1】在片内RAM区中生成十六进制数组Hex:00H、01H、…、0EH、0FH,数组Hex的首地址为10H。【功能2】用DB伪指令在程序中定义Hex数组元素ASCⅡ码表,表首地址用符号地址TABLE表示。【功能3】用MOVCA,@A+PC指令编写查表程序,实现用查表方式将数组Hex的十六进制数转换为ASCⅡ码并存入片内RAM数组Asc中,数组Asc首地址70H。ORG0000HSJMPMAINORG0030HHexEQU10HAscEQU70HMAIN:MOVR0,#HexMOVR1,#AscMOVR7,#16MOVA,#00HLOOP:MOV@R0,AINCAINCR0DJNZR7,LOOPMOVR0,#HexMOVR7,#16Trans:MOVA,@R0ADDA,#05HMOVCA,@A+PCMOV@R1,AINCR0INCR1DJNZR7,TransTABLE:DB0123456789ABCDEFEND2.十进制数1-100累加运算【功能1】产生十进制数1~100,并存入片外RAMDeci数组中,首地址为1001H。【功能2】对Deci数组元素进行累加运算,并将累加和存入内部RAM中60H(存累加和低位)和61H(存累加和高位)单元。ORG0000HSJMPMAINORG0030HDeciEQU1001HMAIN:MOVDPTR,#DeciMOVA,#01HMOVR7,#100LOOP1:MOVX@DPTR,AINCADAAINCDPTRDJNZR7,LOOP1MOVA,#00HADDCA,#00HMOVX@DPTR,AMOVDPTR,#DeciMOVR7,#99MOV60H,#00MOV61H,#00SUM:MOVXA,@DPTRADDA,60HDAAMOV60H,AMOVA,#00ADDCA,61HDAAMOV61H,AINCDPTRDJNZR7,SUMINCDPTRMOVXA,@DPTRADDA,61HDAAMOV61H,AEND3.数据交换程序【功能1】产生十进制数组Deci:0、1、2、…、97、98、99,并存储到片内RAM区中,数组Deci的首地址为10H。【功能2】产生十六进制数组Hex:63H、62H、61H、…、01H、00H,并存储到片外RAM区中,数组Hex的首地址为1000H。【功能3】将片外RAM数组Hex与片内RAM数组Deci交换内容。留意堆栈地址的设置ORG0000HSJMPMAINORG0030HDeciEQU10HHexEQU1000HMAIN:MOVSP,#75HMOVR0,#DeciMOVDPTR,#HexMOVR7,#64HMOVA,#00HMOVR5,#0ACALLLOOPACALLLOOP2ACALLChangeSJMP$LOOP:MOV@R0,AINCADAAINCR0DJNZR7,LOOPMOVA,#63HMOVR7,#64HRETLOOP2:MOVX@DPTR,ADECAINCDPTRDJNZR7,LOOP2MOVR0,#DeciMOVDPTR,#HexMOVR7,#64HRETChange:MOVA,@R0MOVR5,AMOVXA,@DPTRMOV@R0,AMOVA,R5MOVX@DPTR,AINCR0INCDPTRDJNZR7,ChangeRETEND5.定时器的应用DBUFEQU30HORG0STRT:LJMPMAINORG0BHLJMPPTF00ORG030HMAIN:MOVDPTR,#5FFFHMOVA,#0DCHMOVX@DPTR,ALP:MOVXA,@DPTRJNBACC.7,LP;;;;;;MOVA,#00HMOVX@DPTR,AMOVA,#34HMOVX@DPTR,AMOVSP,#60HMOVR0,#39HMOVR7,#06HML1:MOV@R0,#00HINCR0DJNZR7,ML1MOVTMOD,#01HMOVTL0,#06HMOVTH0,#06HSETBTR0MOVIE,#82HMOV40H,#10HML0:LCALLDIRLJMPML0PTF00:PUSHPSWPUSHACCSETBPSW.3MOVTL0,#06HMOVTH0,#06HMOVA,40HDECAMOV40H,AJNZPTFYMOV40H,#10HMOVR0,#39HMOVR7,#6PTFX:MOVA,@R0ADDA,#1DAAMOV@R0,ACJNEA,#0AH,$+3JCPTFYMOV@R0,#0INCR0DJNZR7,PTFXPTFY:POPACCPOPPSWRETIDIR:MOVR3,#06HMOVA,#92HMOVDPTR,#5FFFHMOVX@DPTR,AMOVR1,#39HTY11:MOVA,@R1MOVDPTR,#CODE1MOVCA,@A+DPTRMOVDPTR,#5EFFHMOVX@DPTR,AINCR1DJNZR3,TY11RETCODE1:DB0C0H,0F9H,0A4H,0B0H,99HDB92H,82H,0F8H,80H,90H,88HDB83H,0C6H,0A1H,86H,8EH,8CHDB0C1H,89H,0C7H,0BFH,91HDB00H,0FFHEND5、用中断方式实现定时器T1产生1s控制方式ORG0000HSJMPMAINORG001BHLJMPTimerORG1000HMAIN:MOVTMOD,#20HMOVTL1,#0B0HMOVTL0,#3CHSETBEASETBET1SETBTR1SETBP1.0MOVR7,#10SJMP$Timer:DJNZR7,LOOPCPLP1.0MOVR7,#10MOVTL1,#0B0HMOVTL0,#3CHLOOP:RETIEND6、用查询方式实现定时器T1产生1s控制方式ORG0000HSJMPMAINORG0030HMAIN:SETBP1.0MOVTMOD,#20HMOVTL1,#0B0HMOVTL0,#3CHSETBEASETBET1SETBTR1SETBP1.0MOVR7,#10WAIT:JBCTF1,LOOPSJMPWAITLOOP:DJNZR7,LOOPCPLP1.0MOVR7,#10MOVTL1,#0B0HMOVTL0,#3CHSJMPWAITEND